package com.api.browser.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.api.browser.bean.BrowserValueInfo;
import com.api.browser.bean.ListHeadBean;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.service.BrowserService;
import com.api.browser.service.BrowserValueInfoService;
import com.api.browser.util.*;
import java.text.DecimalFormat;
import com.api.cube.constant.SearchConstant;
import com.api.cube.proxy.ProxyManager;
import com.api.cube.proxy.absclass.IFormModeBrowserProxy;
import com.api.cube.service.CubeSearchService;
import com.api.cube.util.CubeCipherUitl;
import com.api.cube.util.CubeSearchTransMethod;
import com.api.cube.util.CubeSearchTransMethodProxy;
import com.api.doc.detail.util.DocDownloadCheckUtil;
import com.api.formmode.cache.ModeBrowserComInfo;
import com.api.formmode.cache.ModeComInfo;
import com.api.formmode.cache.ModeFormFieldEncryptComInfo;
import com.dangdang.ddframe.rdb.sharding.api.HintManager;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.context.limit.Limit;
import com.dangdang.ddframe.rdb.sharding.parsing.parser.context.limit.LimitValue;
import com.engine.cube.biz.*;
import com.engine.cube.biz.moderight.CubeFieldRightInfo;
import com.engine.cube.util.AddSeclevelUtil;
import com.engine.cube.util.ListUtil;
import com.engine.hrm.biz.OrganizationShowSetBiz;
import com.engine.workflow.biz.wfPathAdvanceSet.BrowserDataDefinitionBiz;
import com.engine.workflow.entity.WeaTableEditComEntity;
import com.engine.workflow.entity.WeaTableEditEntity;
import com.engine.workflow.entity.core.FieldInfoEntity;
import com.engine.workflow.entity.wfPathAdvanceSet.BrowDefFieldConfEntity;
import com.engine.workflow.entity.wfPathAdvanceSet.WfBdfDataEntity;
import com.weaver.formmodel.mobile.ui.manager.CubeBrowserMobileLayoutManager;
import com.weaver.formmodel.util.DateHelper;
import com.weaver.formmodel.util.StringHelper;
import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;
import weaver.cpt.capital.CapitalComInfo;
import weaver.crm.Maint.*;
import weaver.dateformat.DateTransformer;
import weaver.docs.docs.DocComInfo;
import weaver.docs.docs.DocImageManager;
import weaver.docs.senddoc.DocReceiveUnitComInfo;
import weaver.filter.XssUtil;
import weaver.fna.maintenance.BudgetfeeTypeComInfo;
import weaver.fna.maintenance.FnaSystemSetComInfo;
import weaver.formmode.browser.FormModeBrowserSqlwhere;
import weaver.formmode.browser.FormModeBrowserUtil;
import weaver.formmode.customjavacode.CustomJavaCodeRun;
import weaver.formmode.field.ButtonElement;
import weaver.formmode.search.FormModeTransMethod;
import weaver.formmode.service.BrowserInfoService;
import weaver.formmode.service.CommonConstant;
import weaver.formmode.setup.ModeRightForPage;
import weaver.formmode.setup.ModeRightInfo;
import weaver.formmode.setup.ModeSetUtil;
import weaver.formmode.tree.CustomTreeUtil;
import weaver.formmode.view.ModeShareManager;
import weaver.formmode.virtualform.VirtualFormHandler;
import weaver.general.SplitPageParaBean;
import weaver.general.SplitPageUtil;
import weaver.general.StaticObj;
import weaver.general.Util;
import weaver.general.browserData.BrowserManager;
import weaver.hrm.User;
import weaver.hrm.check.JobComInfo;
import weaver.hrm.city.CityComInfo;
import weaver.hrm.company.CompanyComInfo;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.hrm.companyvirtual.CompanyVirtualComInfo;
import weaver.hrm.country.CountryComInfo;
import weaver.hrm.resource.MutilResourceBrowser;
import weaver.hrm.resource.ResourceComInfo;
import weaver.hrm.roles.RolesComInfo;
import weaver.interfaces.workflow.browser.BaseBrowser;
import weaver.interfaces.workflow.browser.Browser;
import weaver.interfaces.workflow.browser.BrowserBean;
import weaver.interfaces.workflow.browser.BrowserForLikeQuery.Util.BrowserLikeUtil;
import weaver.meeting.Maint.MeetingRoomComInfo;
import weaver.proj.Maint.ProjectInfoComInfo;
import weaver.proj.Maint.ProjectTypeComInfo;
import weaver.proj.Maint.WorkTypeComInfo;
import weaver.servicefiles.DataSourceXML;
import weaver.systeminfo.SystemEnv;
import weaver.workflow.field.BrowserComInfo;
import weaver.workflow.request.ResourceConditionManager;
import weaver.workflow.workflow.WorkflowRequestComInfo;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 自定义单选
 * <p>
 * 根据datafrom 判断
 * 1： 则返回 sql
 * 2： WebService
 * 3： 其他
 * <p>
 * 如果是datafrom 是数据源则拿到对应的SQL
 *
 * @author jhy Apr 5, 2017
 */
public class FormmodeBrowserService extends BrowserService {

	private ModeFormFieldEncryptComInfo modeFormFieldEncryptComInfo=new ModeFormFieldEncryptComInfo();

	private boolean isImgSearch = false;
	private String imgField = "";
	private String imgIcon = "";
	private int pagenumber = 0;

	//public FormmodeBrowserService(){
	//    this.isImgSearch = false;
	//    this.imgField = "";
	//    this.imgIcon = "";
	//}
	//
	//public FormmodeBrowserService(Boolean isImgSearch, String imgField, String imgIcon){
	//    this.isImgSearch = isImgSearch;
	//    this.imgField = imgField;
	//    this.imgIcon = imgIcon;
	//}

	@Override
	public Map<String, Object> getMultBrowserDestData(Map<String, Object> params) throws Exception {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		String selectids=Util.null2String(params.get(BrowserConstant.BROWSER_MULT_DEST_SELECTIDS));
		if ("".equals(selectids)) {
			return apidatas;
		}
		apidatas=this.getBrowserData(params);
		apidatas.put(BrowserConstant.BROWSER_RESULT_TYPE, BrowserDataType.LIST_ALL_DATA.getTypeid());
		return apidatas;
	}


	public static Map<String,String> getBrowserInfo(String type){
		Map<String,String> browerMap = null;
		if(!StringHelper.isEmpty(type)){
			if(type.startsWith("browser.")){
				type = type.replace("browser.", "");
			}
			String sql = "select * from mode_browser where showname='"+type+"'";
			RecordSet rs = new RecordSet();
			rs.execute(sql);
			if(rs.next()){
				browerMap = new HashMap<String,String>();
				String[] names = rs.getColumnName();
				for(int i=0;i<names.length;i++){
					String val = rs.getString(names[i]);
					browerMap.put(names[i].toLowerCase(), val);
				}
			}
		}
		return browerMap;
	}

	/**
	 * 获取sql中的字段变量
	 * @param sql
	 * @return
	 */
	public static List<String> getFormFieldArr(String sql) {
		Pattern p = Pattern.compile("(\\$[a-zA-Z][a-zA-Z0-9_]*\\$)");
		Matcher m = p.matcher(sql);
		List<String> list = new ArrayList<String>();
		while (m.find()) {
			String fieldname = m.group();
			sql = sql.replace(fieldname, fieldname.toLowerCase());//替换字段值
			list.add(fieldname.toLowerCase().replace("$", ""));
		}
		return list;
	}

	/**
	 * 获取浏览框的数据
	 *
	 * @param params 参数集合
	 * @return
	 * @throws Exception
	 */
	@Override
	public Map<String, Object> getBrowserData(Map<String, Object> params) throws Exception {
		params = (Map<String, Object>) ProxyManager.proxyExcute( params, IFormModeBrowserProxy.class);
		Map<String, Object> apidatas = new HashMap<String, Object>();
		String id = Util.null2String(params.get("node"));
		String name = Util.null2String(params.get("name"));
		String type = Util.null2String(params.get("type"));//一般前台传来的是browser + 集成数据展示的标识字段+|+触发字段id（可有可无）
		String currenttime = Util.null2String(params.get("currenttime"));//当前时间
		String ismobile = Util.null2String(params.get("ismobile"));//是否移动端);
		this.isMobile="1".equals(ismobile);
		if (this.isMobile) {
			int current = Util.getIntValue(params.get("current")+"",1);
			int pagesize = Util.getIntValue(Util.null2String(params.get("pageSize")),20) ;
			params.put("min", 1+(current-1)*pagesize);
			params.put("max", current*pagesize);
		}
		int start = Util.getIntValue(Util.null2String(params .get("min")), 1);//从第几条数据开始 默认是1
		int end = Util.getIntValue(Util.null2String(params.get("max")), 10);//从第几条数据结束，默认是10
		String showOrder = Util.null2String(params.get("showOrder"));//showOrder = all展示全部，不然分页
		String bts[] = type.split("\\|");
		type = bts[0];
		type = java.net.URLDecoder.decode(type);
		if (type.indexOf("browser.") == -1) {
			type = "browser." + type;
		}
		//联调发现前端页面传递过来的是[object,object]的字符串Map<String, Object> allField = (Map) params.get("allField" );//获取查询语句中的表单中的键值对
		String isreport = Util.null2String(Util.null2String(params.get("isreport")), "0");//是否是报表，1报表
		Map<String, String> allFieldMap = params.containsKey("consearch")?dealFormParams2(params, currenttime,false):dealFormParams(params, currenttime);//处理表单中的键值对，将键key 变成符合规则的$key$,方便替换
		Map<String, String> allFieldTypeMap = params.containsKey("consearch")?dealFormParams3(params, currenttime,false):dealFormParams(params, currenttime);//处理表单中的键值对，将键key 变成符合规则的$key$,方便替换
		String systemIds = Util.null2String(params.get(BrowserConstant.BROWSER_MULT_DEST_SELECTIDS));//已经展示在前台的数据
		List systemIdList = Util.TokenizerString(systemIds, ",");
		//String isTree = Util.null2String(params.get("showType"));//判断是否是树形结构
		String userid = user.getUID() + "";
		Browser browser = (Browser) StaticObj.getServiceByFullname(type, Browser.class);
		apidatas = getSingleBroserData(params, browser, type, isreport, allFieldTypeMap,allFieldMap,  userid, start, end, showOrder, systemIdList);
		return apidatas;
	}



	/**
	 * 返回浏览框的数据集合，单选的是全部，多选的是左边数据集合
	 *
	 * @param params      前台传来的参数集合
	 * @param //type        一般前台传来的是browser + 集成数据展示的标识字段+|+触发字段id（可有可无）
	 * @param isreport    是否报表
	 * @param allFieldMap 表单字段集合
	 * @param //name
	 * @param userid      用户id
	 * @param start       第几条开始
	 * @param end         第几条结束
	 * @param showOrder   是否全部显示
	 * @return apidatas
	 */
	private Map<String, Object> getSingleBroserData(Map<String, Object> params, Browser browser, String browsertype, String isreport, Map<String, String> allFieldTypeMap,Map<String, String> allFieldMap, String userid, int start, int end, String showOrder, List systemIds) throws Exception {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		//初始化Browser浏览框
		//weaver.interfaces.workflow.browser.Browser browser = (weaver.interfaces.workflow.browser.Browser) StaticObj.getServiceByFullname(type, weaver.interfaces.workflow.browser.Browser.class);
		String expendwhere = Util.null2String(params.get("expendwhere"));
		String treeid = Util.null2String(params.get("treeid"));
		String nodataloading = Util.null2String(params.get("nodataloading"));
		String isFromAdvanceSearch = Util.null2String(params.get("isFromAdvanceSearch"));
		String ismobile=Util.null2String(params.get("ismobile"));
		String ew = "";
		int modeId = Util.getIntValue(params.get("modeId")+"");
		String secretLevel = Util.null2String(params.get("secretLevel")+"","4");
		if(!"".equals(expendwhere)){
			try {
				ew = java.net.URLDecoder.decode(expendwhere, "UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}

		Map searchfieldMap = browser.getSearchfieldMap();//获取数据展示集成中浏览框定义的查询字段映射关系
		Map<String, String> searchvaluemap = new HashMap();
		initSearchValueMap(searchfieldMap, params, searchvaluemap);//对请求参数 和 后台获取的Map做匹配，将符合的键值对放入第三个参数中
		Map paramvalues = browser.getParamvalues();
		initSearchValueMap(paramvalues, params, paramvalues);
		browser.setParamvalues(paramvalues);
		String search = browser.getSearch() + " ";//获取查询语句
		String searchByName = browser.getSearchByName() + " ";//获取查询语句
		boolean havebdf =false;//是否配置了数据范围
		if ("1".equals(isreport)) {
			search = removeParam(search);
			searchByName = removeParam(searchByName);
		}
		Map<String, Object> bdfmap = getBrowserDataDefinition(search,params,searchByName);//处理数据定义处的数据范围设置
		search = Util.null2String(bdfmap.get("search"));
		havebdf = (boolean)bdfmap.get("havebdf");
		search = replaceFieldValue(search);
		search = getPARMvalue(search,params);
		//将sql中的表单变量按实际值进行替换
		Map<String, String> searchMap = dealSearch(search, searchByName, allFieldMap, false);
		search = searchMap.get("search");
		searchByName = searchMap.get("searchByName");
		String name1 = "";
		List<ListHeadBean> listHeadBeanList = new ArrayList<ListHeadBean>();
		//------------------------------分割线-----------------------------
		ModeRightInfo modeRightInfo = new ModeRightInfo();
		String src = "";
		Map<String,String> browserMap = getBrowserInfo(browsertype);
		String check_per = "";
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();

		int pagesize = 0;
		String customBrowserId = browserMap.get("customid");
		int browserModeid = -1;
		// CHANGE START
		boolean isModeSharding = false;
		// CHANGE END
		int RecordSetCounts = 0;
		if(browserMap!=null){
			RecordSet rs = new RecordSet();
			RecordSet RecordSet = new RecordSet();
			String customid = browserMap.get("customid");
//        	if(!"".equals(treeid)){//如果是组合查询那边来的,
//        		customid = browserMap.get("id");
//        	}
			ModeBrowserComInfo modeBrowserComInfo = new ModeBrowserComInfo();
			String datashowtype = Util.null2String(modeBrowserComInfo.getDatashowtype(customid));
			// ** 手机端的pageSize 只能获取到20，建模默认10会有问题，isMobile不要重新获取了，会导致加载不到第二页数据 和组件同事那边沟通过
			// CHANGE START
			browserModeid = Util.getIntValue(modeBrowserComInfo.getModeId(customid),-1);
			if (browserModeid != -1) {
				isModeSharding = ShardingActionHelper.isModeSharding(browserModeid);
			}
			// CHANGE END
			if(!"1".equals(datashowtype) && !this.isMobile){
				params.put("pageSize",Util.null2String(modeBrowserComInfo.getPageNumber(customid)));
				browserModeid = Util.getIntValue(modeBrowserComInfo.getModeId(customid),-1);
			}
			pagesize = Util.getIntValue(Util.null2String(params.get("pageSize")),10) ;
			((BaseBrowser)browser).setPageSize(pagesize);
			isImgSearch = StringHelper.isEmpty(treeid) && "1".equals(datashowtype);//组合查询不显示相册
			imgField = Util.null2String(modeBrowserComInfo.getDatashowtypefilefield(customid));
			imgIcon = Util.null2String(modeBrowserComInfo.getDatashowtypefileicon(customid));
			String modeid = "";
			String formID = "";
			int isDisplayDraftData = 0;
			boolean isDraftForm=false;
			rs.execute("select a.defaultsql,a.modeid,a.customname,a.customdesc,a.formid,a.detailtable,a.searchconditiontype,a.isDisplayDraftData,a.javafilename,a.pagenumber,a.norightlist,b.detailkeyfield from mode_custombrowser a left join workflow_bill b on a.formid=b.id where a.id="+customid);
			if(rs.next()){
				formID=Util.null2String(rs.getString("formid"));
				modeid=Util.null2String(rs.getString("modeid"));
				if(!VirtualFormHandler.isVirtualForm(formID)){
					isDisplayDraftData = Util.getIntValue(rs.getString("isDisplayDraftData"),0);
					ModeSetUtil modeSetUtil = new ModeSetUtil();
					isDraftForm = modeSetUtil.isHaveModedatastatusByformid(Util.getIntValue( formID,0));
				}

			}

			//重新计算where和sqlcondition
			String formmodefieldid = Util.null2String(params.get("formmodefieldid"));
			String sqlwhereTemp = "";
			String sqlconditionTemp = "";
			String frombrowserid = "";
			if(!"".equals(formmodefieldid)&&!havebdf){
				rs.executeSql("select expendattr from ModeFormFieldExtend where fieldid="+formmodefieldid);
				if(rs.next()){
					String expendattr = rs.getString(1);
					expendattr = expendattr.replace("&lt;","<");
					expendattr = expendattr.replace("&gt;",">");
					FormModeBrowserSqlwhere fbs = new FormModeBrowserSqlwhere();
					Map<String,Map<String,String>> expendMap = fbs.getApi(expendattr, formmodefieldid);

					//表单中配置的sqlcondition逻辑是将值自动带入到对应浏览框的高级搜索中,默认调用高级搜索处的搜索,不需要在这里处理,正常走条件查询即可  qc 445741
//        			if(expendMap.containsKey("sqlcondition")){
//        				Map<String,String> map = expendMap.get("sqlcondition");
//        				Map<String,String> sqlconditionMap = new HashMap();
//        				if(expendMap.containsKey("sqlconditionMap")){
//        					sqlconditionMap = expendMap.get("sqlconditionMap");
//        				}
//        				sqlwhereTemp = map.get("sql");
//        				Map<String,String> fieldHtmlTypeMap = expendMap.get("fieldHtmlTypeMap");
//        				Iterator<String> it = fieldHtmlTypeMap.keySet().iterator();
//        				String rowIndex = frombrowserid.replace(formmodefieldid,"");
//        				while(it.hasNext()){
//        					String key = it.next();
//        					
//        					String value = Util.null2String(allFieldMap.get("$"+key+"$"));
//        					if(sqlconditionMap!=null&&sqlconditionMap.containsKey(key)){
//        						String conid = sqlconditionMap.get(key);
//        						if(params.containsKey("con"+conid+"_value")){
//        							value = StringHelper.null2String(params.get("con"+conid+"_value"));
//        						}else{
//            						value = "''";
//            					}
//        					}
//        					if(!"".equals(rowIndex)){
//        						String valueTemp = Util.null2String(params.get(key+rowIndex));
//        						if(!"".equals(valueTemp)){
//        							value = valueTemp;
//        						}
//        					}
//        					if("''".equals(value)){
//        						sqlwhereTemp = "";
//        					}else{
//        						sqlwhereTemp = sqlwhereTemp.replace("$"+key+"$",value);
//        					}
//        					
//        				}
//        			}
					if(expendMap.containsKey("sqlwhere")){
						Map<String,String> map = expendMap.get("sqlwhere");
						sqlwhereTemp = map.get("sql");
						Map<String,String> fieldHtmlTypeMap = expendMap.get("fieldHtmlTypeMap");
						Iterator<String> it = fieldHtmlTypeMap.keySet().iterator();
						String rowIndex = frombrowserid.replace(formmodefieldid,"");
						while(it.hasNext()){
							String key = it.next();
							String value = Util.null2String(allFieldMap.get("$"+key.replaceAll("\\.", "_")+"$"));
							if(!"".equals(rowIndex)){
								String valueTemp = Util.null2String(params.get(key.replaceAll("\\.", "_")+rowIndex));
								if(!"".equals(valueTemp)){
									value = valueTemp;
								}
							}
							if("''".equals(value)){
								sqlwhereTemp = "";
							}else{
								sqlwhereTemp = sqlwhereTemp.replace("$"+key+"$",value);
							}
						}
					}
				}
			}
			String isshowall = Util.null2String(params.get("isshowall"));//isshowall表示取消sql条件判断
			String sqlwhere="";
			String formid="";//引用这个浏览框的表单id
			String sql_formid = "select billid from  workflow_billfield  where  id =?";
			rs.executeQuery(sql_formid,formmodefieldid );
			if(rs.next()){
				formid=rs.getString(1);
			}
			String Search = browser.getSearch();
			Map<String, Object> bdatafmap = getBrowserDataDefinition(Search,params,searchByName);//处理数据定义处的数据范围设置
			Search = Util.null2String(bdatafmap.get("search"));
			Search = getPARMvalue(Search,params);
			BrowserManager bm=new BrowserManager();
			Search=bm.replaceModeDefaultValue(userid, Search);
			//============================================虚拟表基础数据====================================
			boolean isVirtualForm = VirtualFormHandler.isVirtualForm(formID);
			String vdatasource = "";	//虚拟表单数据源
			String vprimarykey = "";	//虚拟表单主键列名称
			String vdatasourceDBtype = "";	//数据库类型
			String vformtype="";
			String vsql="";
			Map<String, Object> vFormInfo = new HashMap<String, Object>();
			if(isVirtualForm){
				vFormInfo = VirtualFormHandler.getVFormInfo(formID);
				vdatasource = Util.null2String(vFormInfo.get("vdatasource"));	//虚拟表单数据源
				vprimarykey = Util.null2String(vFormInfo.get("vprimarykey"));	//虚拟表单主键列名称
				vformtype = Util.null2String(vFormInfo.get("vformtype"));
				vsql = Util.null2String(vFormInfo.get("vsql"));
				DataSourceXML dataSourceXML = new DataSourceXML();
				vdatasourceDBtype = dataSourceXML.getDataSourceDBType(vdatasource);
			}else{// CHANGE START
				if (isModeSharding) {
					vdatasource = ShardingHelper.SHARDING_POOL_NAME;
				}
				// CHANGE END
				vdatasourceDBtype = RecordSet.getDBType();
			}

			if(isVirtualForm){//需要针对 sql 语句做的虚拟表单做处理
				if("2".equals(vformtype)){
					Search=Search.toLowerCase().replace(vsql.toLowerCase(),"QCweaver");//vsql中如果有where 就会干扰
				}
			}
			if ("1".equals(isreport)) {
				Search = removeParam(Search + " ");
			}
			for(int i=0;i<systemIds.size();i++){
				check_per += "".equals(Util.null2String(systemIds.get(i))) ? "" : ","+Util.null2String(systemIds.get(i));
			}
			if(check_per.trim().startsWith(",")){
				check_per = check_per.substring(1);
			}
			if("".equals(check_per)) {//#923839如果是已选数据，无条件查询sql后的条件不需要。
				if(Search.toLowerCase().indexOf("where")!=-1){
					sqlwhere = Search.substring(Search.toLowerCase().indexOf("where")+5);
					if(sqlwhere.matches("(?i).+[)\\s]or[(\\s].+")){ //如果有or，再包裹一层括号
						sqlwhere = " ( "+sqlwhere+" ) ";
					}
					if(sqlwhere.indexOf("$")!=-1){
						if(!sqlwhere.contains(".") || sqlwhere.contains("=")){
							sqlwhere = replaceFieldValue(sqlwhere);
						}
						Map map = dealSearch_(sqlwhere, "",allFieldTypeMap, allFieldMap, false,Util.null2String(params.get("billid")),formid);
						sqlwhere = Util.null2String(map.get("search"));
					}
				}
			}
			String _sqlwhere = sqlwhereTemp;
			//_sqlwhere传递过来已经是加密的形式，所以先解密和Search中的where条件合并后，再加密
			if(!_sqlwhere.equals("")){
				if(!sqlwhere.equals("")){
					sqlwhere += " and "+_sqlwhere;
				}else{
					sqlwhere = _sqlwhere;
				}
			}

			//如果传了isshowall参数，则过滤sql中所有$$类型的参数
			if("1".equals(isshowall)){
				nodataloading = "0";
				sqlwhere = BrowserLikeUtil.runSqlBeforePro(sqlwhere+" ").trim();
			}else if(this.isMobile){//移动端不支持searchParams，因此不支持不加在数据功能
				nodataloading = "0";
			}

			String sqlcondition = sqlconditionTemp;

			//链接地址中sqlwhere
			String sqlwhereparam = sqlwhere;


			int pageindex = Util.getIntValue(Util.null2String(params.get("pageindex")) , 1) ;
			if (!params.containsKey("current")){
				pageindex = (Util.getIntValue(Util.null2String(params.get("min")) , 0)-1)/pagesize+1;
			}
			((BaseBrowser)browser).setPageIndex(pageindex);
			if(pagesize <1) pagesize=10;
			String isCustomPageSize = Util.null2String(params.get("isCustomPageSize"));




			//============================================browser框基础数据====================================
			boolean issimple=true;
			String isbill="1";
			int viewtype=0;
			int opentype = 0;
			String defaultsql="";
			String searchconditiontype = "1";
			String javafilename = "";
			String javafileaddress = "";
			String showfield="";
			String fromSql;
			String formmodeid="0";
			String tablename="";
			String orderby = "t1.id";
			String norightlist = "";
			String detailtable = "";
			String detailkeyfield = "";
			String maintableAlias="t1";
			String detailtableAlias="d1";
			String detailfieldAlias="d_";
			String backfields = " t1.id,t1.formmodeid,t1.modedatacreater,t1.modedatacreatertype,t1.modedatacreatedate,t1.modedatacreatetime ";
			if(isDraftForm){
				backfields += ",t1.modedatastatus";
			}

			rs.execute("select a.defaultsql,a.modeid,a.customname,a.customdesc,a.formid,a.detailtable,a.searchconditiontype,a.javafilename,a.javafileaddress,a.pagenumber,a.norightlist,b.detailkeyfield from mode_custombrowser a left join workflow_bill b on a.formid=b.id where a.id="+customid);
			FormModeTransMethod FormModeTransMethod = new FormModeTransMethod();
			CubeSearchTransMethod cubeSearchTransMethod = new CubeSearchTransMethodProxy().proxy();
			if(rs.next()){
				formID=Util.null2String(rs.getString("formid"));
				formmodeid=Util.null2String(rs.getString("modeid"));
				defaultsql = Util.toScreenToEdit(rs.getString("defaultsql"),user.getLanguage()).trim();
				defaultsql = getPARMvalue(defaultsql,params);
				defaultsql = FormModeTransMethod.getDefaultSql(user,defaultsql);

				searchconditiontype = Util.null2String(rs.getString("searchconditiontype"));
				searchconditiontype = searchconditiontype.equals("") ? "1" : searchconditiontype;
				javafilename = Util.null2String(rs.getString("javafilename"));
				javafileaddress = Util.null2String(rs.getString("javafileaddress"));
				if(pagesize==10&&isCustomPageSize.equals("")){//首次加载或不改变页数
					pagesize = Util.getIntValue(Util.null2String(rs.getString("pagenumber")),10);
				}
				norightlist = Util.null2String(rs.getString("norightlist"));
				detailtable = Util.null2String(rs.getString("detailtable"));
				detailkeyfield = Util.null2String(rs.getString("detailkeyfield"));
			}



			// 判断明细表是否存在
			if(!"".equals(detailtable)){

				rs.executeQuery("select count(1) cou from workflow_billdetailtable where tablename=?",detailtable);
				if(rs.next() && rs.getInt("cou")<=0){
					throw new Exception(SystemEnv.getHtmlLabelName(503095,user.getLanguage()));//浏览框明细表不存在，请检查浏览框配置！
				}
			}

			if(pageindex<=1){
				if(params.containsKey("min")&&params.containsKey("max")){
					int min = Util.getIntValue(Util.null2String(params.get("min")) , 0) ;
					int max = Util.getIntValue(Util.null2String(params.get("max")) , 0) ;
					if(min>0&&max>=min){
						//pagesize = max - min+1;
						pageindex = (min-1)/pagesize+1;
					}
				}
			}




			//============================================表单名称====================================
			rs.executeSql("select tablename from workflow_bill where id = " + formID);
			if (rs.next()){
				tablename = rs.getString("tablename");
			}
			if(isVirtualForm){
				if("2".equals(vformtype)){
					tablename="("+vsql+")";
				}else{
					tablename= VirtualFormHandler.getRealFromName(tablename);
				}
			}
			//============================================自定义查询条件====================================
			String sqlwhere_con="";
			boolean isoracle = vdatasourceDBtype.equals("oracle") ;
			boolean isdb2 = vdatasourceDBtype.equals("db2") ;
			boolean ismysql = vdatasourceDBtype.contains("mysql") ;
			boolean ispostgresql = vdatasourceDBtype.equals("postgresql") ;
			String createrid=Util.null2String(params.get("createrid"));
			String creatertype=Util.null2String(params.get("creatertype"));
			String fromdate=Util.null2String(params.get("fromdate"));
			String todate=Util.null2String(params.get("todate"));



			String sql = "";
			String fields = "mode_CustombrowserDspField.shownamelabel ,mode_CustombrowserDspField.queryorder " +
					",mode_CustombrowserDspField.showorder ,workflow_billfield.id as id" +
					",workflow_billfield.fieldname as name,workflow_billfield.fielddbtype as dbtype " +
					",workflow_billfield.selectitem as selectitem,workflow_billfield.linkfield as linkfield" +
					",workflow_billfield.fieldhtmltype as httype,workflow_billfield.childfieldid as childfieldid" +
					",workflow_billfield.type as type,mode_CustombrowserDspField.conditionTransition as conditionTransition" +
					",workflow_billfield.viewtype,mode_CustombrowserDspField.isquicksearch"
					+",mode_CustombrowserDspField.isquery";
			if(RecordSet.getDBType().equals("oracle")){
				fields += ",to_char(workflow_billfield.fieldlabel) as label";
			}else if(RecordSet.getDBType().equals("mysql")){
				fields += ",convert(workflow_billfield.fieldlabel , char) as label";
			}
			else if(RecordSet.getDBType().equals("postgresql")){
				fields += ",to_char(workflow_billfield.fieldlabel) as label";
			}
			else{
				fields += ",convert(varchar,workflow_billfield.fieldlabel) as label";
			}
			sql = "select * from (select "+fields+" from workflow_billfield,mode_CustombrowserDspField,mode_custombrowser where mode_CustombrowserDspField.customid=mode_custombrowser.id and mode_custombrowser.id="+customid+" and workflow_billfield.billid='"+formID+"' and workflow_billfield.id=mode_CustombrowserDspField.fieldid ";
			sql+=" union select shownamelabel,queryorder,showorder,fieldid as id,'' as name,'' as dbtype,0 as selectitem,0 as linkfield,'' as httype,0 as childfieldid,0 as type,0 as conditionTransition,0 as viewtype ,isquicksearch,isquery,'' as label from mode_CustombrowserDspField where fieldid in(-1,-2,-3,-4,-5,-6,-7,-8,-9,-10) and customid="+customid;
			sql+=") a order by a.queryorder,a.showorder,a.id";
			RecordSet.execute(sql);

			sqlwhere_con = getSearchSqlWhere(params, RecordSet, maintableAlias, detailtableAlias, vdatasourceDBtype, sqlwhere_con, isoracle, isdb2,true);
			RecordSet.beforFirst();
			String sqlwhere_custom = getSearchSqlWhere(params, RecordSet, maintableAlias, detailtableAlias, vdatasourceDBtype, "", isoracle, isdb2,false);
			if(!"".equals(sqlwhere_custom)){
				String temp = "";
				if (!"".equals(sqlwhere_custom) && !sqlwhere_custom.startsWith("and")){
					temp = "and ";
				}
				defaultsql += "".equals(defaultsql)?" 1=1 " + temp + sqlwhere_custom: sqlwhere_custom;
			}

			//============================================需要显示的字段====================================
			ModeShareManager ModeShareManager = new ModeShareManager();
			Map<String,Object> showfieldMap1=new LinkedHashMap<String,Object>();
			if(isVirtualForm){
				backfields = " t1." + vprimarykey + " ";
			} else {
				rs.executeSql("select * from "+tablename+ " a where 1=2 ");
				String[] columnName = rs.getColumnName();
				//如果表单里修改人和修改日期时间字段需要返回
				if(StringHelper.containsIgnoreCase(columnName, "modedatamodifier")){
					backfields += ",t1.modedatamodifier";
				}
				if(StringHelper.containsIgnoreCase(columnName, "modedatamodifydatetime")){
					backfields += ",t1.modedatamodifydatetime";
				}
				if(StringHelper.containsIgnoreCase(columnName, "seclevel")){//密级字段
					backfields += ",t1.seclevel";
				}
				// CHANGE START
				if (StringHelper.containsIgnoreCase(columnName, ShardingHelper.KEY_FORM_BIZ_ID)) {
					backfields += String.format(",t1.%s", ShardingHelper.KEY_FORM_BIZ_ID);
				}
				// CHANGE END
				boolean hasFormmodeid = false;
				for(int j = 0; j<columnName.length;j++) {
					if("formmodeid".equalsIgnoreCase(columnName[j])) {
						hasFormmodeid = true;
						break;
					}
				}
				if(!hasFormmodeid){
					backfields = " t1.id ";
				}
			}
			String pkfield = "";//主键：原有的字段名
			String pkfieldTemp = "";//主键：如果是子表，则加上表的别名d_,用来判断，哪一列是主键字段
			String isShowSql=" (mode_custombrowserdspfield.isshow='1' or mode_custombrowserdspfield.ispk='1') and ";
			if("1".equals(Util.null2String(params.get("ismobile")))){
				isShowSql="";
			}
			sql = "select workflow_billfield.id as id,workflow_billfield.fieldname as name,workflow_billfield.fieldlabel as label,mode_custombrowserdspfield.shownamelabel,workflow_billfield.fielddbtype as dbtype ,workflow_billfield.fieldhtmltype as httype, workflow_billfield.type as type,mode_custombrowserdspfield.showorder,mode_custombrowserdspfield.istitle,mode_custombrowserdspfield.ispk,workflow_billfield.viewtype,mode_custombrowserdspfield.colwidth,mode_custombrowserdspfield.mobilewidth,mode_custombrowserdspfield.isshow" +
					" from workflow_billfield,mode_custombrowserdspfield,Mode_CustomBrowser where mode_custombrowserdspfield.customid=Mode_CustomBrowser.id and Mode_CustomBrowser.id="+customid+
					"  and "+isShowSql+" workflow_billfield.billid="+formID+"  and   workflow_billfield.id=mode_custombrowserdspfield.fieldid" +
					" union select mode_custombrowserdspfield.fieldid as id,'1' as name,2 as label, shownamelabel,'3' as dbtype, '4' as httype,5 as type ,mode_custombrowserdspfield.showorder,mode_custombrowserdspfield.istitle,mode_custombrowserdspfield.ispk,0 as viewtype,mode_custombrowserdspfield.colwidth,mode_custombrowserdspfield.mobilewidth,mode_custombrowserdspfield.isshow" +
					" from mode_custombrowserdspfield ,Mode_CustomBrowser where mode_custombrowserdspfield.customid=Mode_CustomBrowser.id and Mode_CustomBrowser.id="+customid+
					"   and "+isShowSql+" mode_custombrowserdspfield.fieldid<0" +
					" order by istitle desc,showorder asc,id asc";
			RecordSet.executeSql(sql);
			String showfieldname = "";
			String titleviewtype="";
			boolean hasPk = false;
			int sumColWidth = 0;
			Map<String,Integer> fieldColWidthMap = new HashMap<String,Integer>();
			int zerocount = 0;

			while (RecordSet.next()){
				boolean isTitleCol = false;
				String key = "";
				String htmltype="";
				String type="";
				String ispk="";
				int label = RecordSet.getInt("label");
				int shownamelabel = Util.getIntValue(RecordSet.getString("shownamelabel"),0);
				if(shownamelabel!=0){
					label = shownamelabel;
				}
				int fieldColWidth = (int)Util.getDoubleValue(RecordSet.getString("colwidth"),0);
				String id=Util.null2String(RecordSet.getString("id"));
				if("-1".equals(id)){
					showfieldMap1.put("modedatacreatedate", "modedatacreatetime");
					showfieldname +=",modedatacreatetime";
					key = "modedatacreatedate";
					if(shownamelabel==0){
						label = 722;
					}
				}else if("-3".equals(id)){
					showfieldMap1.put("id", "id");
					showfieldname +=",id";
					key = "id";
					if(shownamelabel==0){
						label = 81287;
					}
				}else if("-2".equals(id)){
					showfieldMap1.put("modedatacreater", "modedatacreatertype");
					showfieldname +=",modedatacreatertype";
					key = "modedatacreater";
					if(shownamelabel==0){
						label = 882;
					}
				}else if("-5".equals(id)){
					showfieldname +=",modedatastatus";
					key = "modedatastatus";
					if(shownamelabel==0){
						label = 385992;
					}
					showfieldMap1.put(key,"");
				}else if("-7".equals(id)){
					showfieldMap1.put("modedatamodifier", "modedatacreatertype");
					showfieldname +=",modedatacreatertype";
					key = "modedatamodifier";
					if(shownamelabel==0){
						label = 3002;
					}
				}else if("-8".equals(id)){
					showfieldname +=",modedatamodifydatetime";
					key = "modedatamodifydatetime";
					if(shownamelabel==0){
						label = 516915;
					}
					showfieldMap1.put(key,"");
				}else if(id.equals("-9")){
					showfieldname +=",seclevel";
					key = "seclevel";
					if(shownamelabel==0){
						label = 526505;
					}
					showfieldMap1.put(key,"");
				}
				// CHANGE START
				else if (id.equals("-10")) {
					// 业务ID
					showfieldname += String.format(",%s", ShardingHelper.KEY_FORM_BIZ_ID);
					key = ShardingHelper.KEY_FORM_BIZ_ID;
					if(shownamelabel==0){
						label = 535882;
					}
					showfieldMap1.put(key,"");
				}
				// CHANGE END
				else{
					String name=Util.null2String(RecordSet.getString("name"));
					String dbtype=Util.null2String(RecordSet.getString("dbtype"));
					htmltype = RecordSet.getString("httype");
					type = RecordSet.getString("type");
					if("2".equals(htmltype) && "1".equals(datashowtype)){//相册列表不显示多行文本
						continue;
					}
					String istitle = RecordSet.getString("istitle");
					String hreflink = RecordSet.getString("hreflink");
					ispk = RecordSet.getString("ispk");
					int field_viewtype = Util.getIntValue(RecordSet.getString("viewtype"),0);
					viewtype = field_viewtype;
					String fieldAlias=name;
					String tableAlias=maintableAlias;
					if(field_viewtype==1){
						tableAlias=detailtableAlias;
						fieldAlias=detailfieldAlias+name;
					}
					key = fieldAlias;

					if("1".equals(ispk)){
						hasPk = true;
						pkfield = name;
						pkfieldTemp = key;
					}

					if(istitle.equals("1")||istitle.equals("2")){
						titleviewtype = field_viewtype+"";
						isTitleCol = true;
					}
					showfieldname +=","+name;
					if(dbtype.toLowerCase().equals("text")){
						if(isoracle){
							showfield=showfield+","+"to_char("+tableAlias+"."+name+") as "+fieldAlias;
						}else if(ismysql){
							showfield=showfield+","+"convert("+tableAlias+"."+name+",char) as "+fieldAlias;
						}
						else if(ispostgresql){
							showfield=showfield+","+"to_char("+tableAlias+"."+name+") as "+fieldAlias;
						}
						else{
							showfield=showfield+","+"convert(varchar(max),"+tableAlias+"."+name+") as "+fieldAlias;
						}
					}else{
						if((backfields.toUpperCase()+",").indexOf((tableAlias+"."+name+" ").toUpperCase())==-1 &&
								(backfields.toUpperCase()+",").indexOf((tableAlias+"."+name+",").toUpperCase())==-1 ){
							showfield=showfield+","+tableAlias+"."+name+" as "+fieldAlias;
						}
					}
					if(isVirtualForm){
						if(formmodeid.equals("0")){
							formmodeid = "virtual";
						}
					}
					String para3="column:id+"+id+"+"+htmltype+"+"+type+"+"+user.getLanguage()+"+"+isbill+"+"+dbtype+"+"+istitle+"+"+formmodeid+"+"+formID+"+"+viewtype+"+"+opentype+"+"+customid+"+fromsearchlist"+"+"+hreflink;
					showfieldMap1.put(fieldAlias,para3);
				}
				String showname = SystemEnv.getHtmlLabelName(label, user.getLanguage());
				ListHeadBean headCol = new ListHeadBean(key, showname, isTitleCol ? 1 : 0, isTitleCol ? BoolAttr.TRUE : BoolAttr.FALSE);
				if (isTitleCol) {
					headCol.setIsInputCol(BoolAttr.TRUE);
				}
				if(hasPk&&pkfieldTemp.equalsIgnoreCase(key)){
					headCol.setIsPrimarykey(BoolAttr.TRUE);
				}
//				if(htmltype.equals("4")&&type.equals("1")){//check框
//					headCol.setHtmlType(Util.getIntValue(htmltype,0));
//					headCol.setType(Util.getIntValue(type));
//				}

				fieldColWidthMap.put(key, fieldColWidth);
				if(fieldColWidth<=12){
					sumColWidth += 100;//百分比过小时默认宽度是100px
					zerocount++;
				}else{
					sumColWidth += (fieldColWidth*7.8);
				}
				if(this.isMobile){
					headCol.setWidth(Util.getDoubleValue(RecordSet.getString("mobilewidth"),0)+"px");
				}
				String isshow = Util.null2String(RecordSet.getString("isshow"));
				if ("1".equals(isshow)) {
					listHeadBeanList.add(headCol);
				}
				if(!"1".equals(isshow)&&"1".equals(ispk)){//主键不展示的时候，需要添加到columns
					headCol.setHide(BoolAttr.TRUE);
					listHeadBeanList.add(headCol);
				}
			}
			int sumwidth = sumColWidth+10*zerocount;
			double p = sumwidth/100.0;//比例
			int columnSize=listHeadBeanList.size();
			for(int j=0;j<columnSize;j++){
				ListHeadBean lhb = listHeadBeanList.get(j);
				String key = lhb.getDataIndex();
				int w = fieldColWidthMap.get(key);
				w=(int) (w<=12?100:(w*7.8));
				if(sumwidth>=784){//大于等于784,按像素算,否则按百分比算
					lhb.setOldWidth(w+"px");
				}else{
					w=(int) ((w+10)/p);
					lhb.setOldWidth(w+"%");
				}
			}



			showfieldMap1.put( BrowserConstant.BROWSER_LIST_CHECKBOX_FIELDNAME, "");


			List<User> lsUser = modeRightInfo.getAllUserCountList(user);
			backfields=backfields+showfield;
			boolean needVirtualRight=isVirtualForm&&norightlist.equals("0")&&ListUtil.haveFormmodeidAndID(formID);
			Map<String, Object> preCheck = modeRightInfo.preCheckUserRight(user,Util.getIntValue(formmodeid,0));
			boolean hasUserRight=(boolean) preCheck.get("isview");
			if(isVirtualForm&&!needVirtualRight){	//是虚拟表单
				fromSql  = " from "+tablename+" t1 ";
				if(sqlwhere.equals("")){
					sqlwhere = " where 1=1";
				}
				String timeStr=DateHelper.getCurDateTime();
				sqlwhere+=" and '"+timeStr+"'='"+timeStr+"' ";
			}else if(norightlist.equals("1")||(!isVirtualForm&&hasUserRight)){
				if(titleviewtype.equals("1")){//标题是明细表中的字段
					fromSql  = " from "+detailtable+" "+detailtableAlias ;
					if(!"".equals(detailtable)){
						fromSql+=" inner join "+tablename+" "+maintableAlias+" on t1.id="+detailtableAlias+"."+detailkeyfield+" ";
					}
					if(formmodeid.equals("")||formmodeid.equals("0")){//浏览框中没有设置模块
						sqlwhere = " where 1=1 ";
					}else{
						sqlwhere = " where t1.formmodeid="+formmodeid+" ";
					}
				}else{
					fromSql  = " from "+tablename+" "+maintableAlias ;
					if(!"".equals(detailtable)){
						fromSql+=" inner join "+detailtable+" "+detailtableAlias+" on t1.id="+detailtableAlias+"."+detailkeyfield+" ";
					}
					if(formmodeid.equals("")||formmodeid.equals("0")){//浏览框中没有设置模块
						sqlwhere = " where 1=1 ";
					}else{
						sqlwhere = " where t1.formmodeid="+formmodeid+" ";
					}
				}
			}else{
				CubeSearchService cubeSearchService = new CubeSearchService();
				String rightsql = "";
				if(formmodeid.equals("")||formmodeid.equals("0")||needVirtualRight){//浏览框中没有设置模块
					RecordSet rs1 = new RecordSet();
					String sqlStr1 = "select id,modename from modeinfo where formid="+formID+" order by id";
					if (needVirtualRight) {
						sqlStr1="select distinct formmodeid id from "+tablename;
						if("2".equals(vformtype)){
							sqlStr1+=" f ";
						}
						rs1.executeQueryWithDatasource(sqlStr1, vdatasource);
					}else{
						rs1.executeSql(sqlStr1);
					}
					while(rs1.next()){
						String mid = rs1.getString("id");
						ModeShareManager.setModeId(Util.getIntValue(mid,0));
						for(int j=0;j<lsUser.size();j++){
							User tempUser = lsUser.get(j);
							String tempRightStr = ModeShareManager.getShareDetailTableByUser("formmode",tempUser);
							if(rightsql.isEmpty()){
								rightsql += tempRightStr;
							}else {
								rightsql += " union  all  SELECT sourceid,sharelevel from "+ tempRightStr +" temp"+mid;
							}
							String roleLimitedRightsql = cubeSearchService.getRoleLimitedRightsql(mid+"",tempUser,tablename);
							if(roleLimitedRightsql.isEmpty()){
								rightsql += roleLimitedRightsql;
							}else {
								if (rs.getDBType().equals("mysql")) {//mysql两个大结果集直接union all会报错
									rightsql += " union  all SELECT  sourceid,sharelevel from ("+ roleLimitedRightsql+") as temp"+j;
								}else {
									rightsql += " union  all "+ roleLimitedRightsql;
								}
							}
//        	                //针对字段相关的权限
//        	                CubeFieldRightInfo cubeFieldRightInfo=new CubeFieldRightInfo(Util.getIntValue(mid),Util.getIntValue(formID),tempUser);
//        	        		String fieldRightSql=cubeFieldRightInfo.getWhereSqlForRolelimited(false);
//        	        		rightsql=cubeFieldRightInfo.plusRightSql(rightsql,fieldRightSql);
						}
					}
					if(!rightsql.isEmpty()){
						rightsql = " (SELECT  sourceid,MAX(sharelevel) AS sharelevel from ( "+rightsql+" ) temptable group by temptable.sourceid) ";
					}
				}else{
					ModeShareManager.setModeId(Util.getIntValue(formmodeid,0));
					for(int j=0;j<lsUser.size();j++){
						User tempUser = (User)lsUser.get(j);
						String tempRightStr = ModeShareManager.getShareDetailTableByUser("formmode",tempUser);
						if(rightsql.isEmpty()){
							rightsql += tempRightStr;
						}else {
							if (rs.getDBType().toLowerCase().contains("mysql")) {//mysql两个大结果集直接union all会报错
								rightsql += " union  all select  sourceid,sharelevel  from  ("+tempRightStr+") as temp"+j ;
							}else{
								rightsql += " union  all "+ tempRightStr;
							}
						}
						String roleLimitedRightsql = cubeSearchService.getRoleLimitedRightsql(formmodeid+"",tempUser,tablename);
						if(roleLimitedRightsql.isEmpty()){
							rightsql += roleLimitedRightsql;
						}else {
							if (rs.getDBType().equals("mysql")) {//mysql两个大结果集直接union all会报错
								rightsql += " union  all SELECT  sourceid,sharelevel from ("+ roleLimitedRightsql+") as t"+j;
							}else {
								rightsql += " union  all "+ roleLimitedRightsql;
							}
						}
//    	                //针对字段相关的权限
//    	                CubeFieldRightInfo cubeFieldRightInfo=new CubeFieldRightInfo(Util.getIntValue(formmodeid),Util.getIntValue(formID),tempUser);
//    	        		String fieldRightSql=cubeFieldRightInfo.getWhereSqlForRolelimited(false);
//    	        		rightsql=cubeFieldRightInfo.plusRightSql(rightsql,fieldRightSql);
					}

					if(!rightsql.isEmpty()){
						rightsql = " (SELECT  sourceid,MAX(sharelevel) AS sharelevel from ( "+rightsql+" ) temptable group by temptable.sourceid) ";
					}
				}

				if(titleviewtype.equals("1")){//标题是明细表中的字段
					fromSql  = " from "+detailtable+" "+detailtableAlias;
					if(!"".equals(detailtable)){
						fromSql+=" inner join "+tablename+" "+maintableAlias+" on t1.id="+detailtableAlias+"."+detailkeyfield+" ";
					}
				}else{
					fromSql  = " from "+tablename+" t1 ";
					if(!"".equals(detailtable)){
						fromSql+=" inner join "+detailtable+" "+detailtableAlias+" on t1.id="+detailtableAlias+"."+detailkeyfield+" ";
					}
				}
				if (!"".equals(rightsql)) {
					fromSql += ","+rightsql+" t2 " ;
					if(sqlwhere.equals("")){
						sqlwhere = " where t1.id = t2.sourceid";
					}else{
						sqlwhere += " and t1.id = t2.sourceid";
					}
				}
			}
			if (hasUserRight) {
				sqlwhere+=ModeRightInfo.getStatusSqlWhere(SearchConstant.MAIN_TABLE_ALIAS,tablename, user.getUID());
			}
			if(!"".equals(sqlwhereparam)){
				//sqlwhereparam=URLDecoder.decode(sqlwhereparam);
				sqlwhere+=" and "+sqlwhereparam.trim();
			}
			sqlwhere_con=sqlwhere_con.trim();
			if(!"".equals(sqlwhere_con)){
				if(sqlwhere_con.toLowerCase().trim().startsWith("and ")){
					sqlwhere+=" "+sqlwhere_con;
				}else{
					sqlwhere+=" and "+sqlwhere_con;
				}
			}

			String sqlCondition = "";
			if(searchconditiontype.equals("2")){	//java file
				if(!javafileaddress.equals("")){
					String classFullName =javafileaddress;
					Map<String, Object> param = new HashMap<String, Object>();
					param.put("user", user);
					param.put("extensionParam", params);//将参数传入java类中
					Object result = CustomJavaCodeRun.run(classFullName, param);
					if(!"error".equals(Util.null2String(result))){
						sqlCondition = Util.null2String(result);
					}
				}else if(!javafilename.equals("")){
					Map<String, String> sourceCodePackageNameMap = CommonConstant.SOURCECODE_PACKAGENAME_MAP;
					String sourceCodePackageName = sourceCodePackageNameMap.get("3");
					String classFullName = sourceCodePackageName + "." + javafilename;

					Map<String, Object> param = new HashMap<String, Object>();
					param.put("user", user);
					param.put("extensionParam", params);//将参数传入java类中
					Object result = CustomJavaCodeRun.run(classFullName, param);
					sqlCondition = Util.null2String(result);
				}
			}else{
				sqlCondition = defaultsql;
			}

			if(!sqlCondition.equals("")){
				sqlCondition = "(" + sqlCondition + ")";
				if("".equals(sqlwhere)){
					sqlwhere = "1=1";
				}
				sqlwhere = sqlwhere + " and "+sqlCondition;
			}
			if(isDraftForm&&isDisplayDraftData==0){
				sqlwhere = sqlwhere+" and t1.modedatastatus is not null and t1.modedatastatus<>1 ";
			}

			String sqlprimarykey = "t1.id";
			String pkfieldname = isModeSharding ? ShardingHelper.KEY_FORM_BIZ_ID : "id";
			if(isVirtualForm){	//虚拟表单
				sqlprimarykey = "t1." + vprimarykey;
				pkfieldname = vprimarykey;
				pkfield = vprimarykey;
				BrowserInfoService browserInfoService=new BrowserInfoService();
				orderby = browserInfoService.getOrderSQL(customid);
				if(StringHelper.isEmpty(orderby)){
					orderby = "t1." + vprimarykey;
				}
			} else { //实际表单
				BrowserInfoService browserInfoService=new BrowserInfoService();
				orderby = browserInfoService.getOrderSQL(customid);
				if(rs.getDBType().toLowerCase().indexOf("sqlserver")!=-1){
					orderby = orderby.replaceAll("(d)([0-9]*)(\\.)","d_");
				}
				if(titleviewtype.equals("1")){
					// CHANGE START
					if (isModeSharding) {
						pkfieldname = detailfieldAlias + ShardingHelper.KEY_DETAIL_BIZ_ID;
					} else {
						pkfieldname=detailfieldAlias+"id";
					}
					// CHANGE END
				}
				if("".equals(pkfield)){
					if(titleviewtype.equals("1")){
						// CHANGE START
						if (isModeSharding) {
							sqlprimarykey = detailtableAlias + "." + ShardingHelper.KEY_DETAIL_BIZ_ID;
						} else {
							sqlprimarykey = detailtableAlias+".id";
						}
						// CHANGE END
					}else{
						sqlprimarykey = "t1.id";
					}
				}else{
					if(titleviewtype.equals("1")){
						sqlprimarykey = detailtableAlias+"."+pkfield;
						pkfieldname = detailfieldAlias+pkfield;
						vprimarykey = pkfieldname;
					}else{
						sqlprimarykey = "t1."+pkfield;
						pkfieldname = pkfield;
						vprimarykey = pkfieldname;
					}
				}

			}

			backfields+=","+sqlprimarykey+" as hiddenfield ";
			if(titleviewtype.equals("1")){
				if(backfields.indexOf(sqlprimarykey+" as "+pkfieldname)==-1){
					backfields += ","+sqlprimarykey+" as "+pkfieldname;
				}
			}

			String tableAlias=maintableAlias;
			if(titleviewtype.equals("1")){
				tableAlias=detailtableAlias;
			}

//            if(src.equalsIgnoreCase("dest")){//右侧已选择列表的sql条件
			if(!"".equals(check_per)){
				String dbtypeStr = rs.getDBType();
				if(isVirtualForm){
					dbtypeStr = rs.getDBType(vdatasource);
					check_per = check_per.replaceAll(",", "','");
				}

				if(dbtypeStr.equals("oracle")){//Oracle这里改变in的写法，否则Oracle 10g 版本的数据库会有bug 
					if(isVirtualForm){
						sqlwhere += " and exists (select 1 from "+tablename+" a where t1."+vprimarykey+" in ('"+check_per+"')) ";
					}else{

						if(!"".equals(pkfield)){
							check_per = check_per.replaceAll(",", "','");
							sqlwhere += " and exists (select 1 from "+tablename+" a where  "+tableAlias+"."+pkfield+" in ('"+check_per+"')) ";
						}else{
							sqlwhere += " and exists (select 1 from "+tablename+" a where  "+tableAlias+".id in ("+check_per+")) ";
						}
					}
				}else{
					if(isVirtualForm){
						sqlwhere += " and t1."+vprimarykey+" in ('"+check_per+"')";
					}else{
						if(!"".equals(pkfield)){
							check_per = check_per.replaceAll("'", "''");
							check_per = check_per.replaceAll(",", "','");
							sqlwhere += " and "+tableAlias+"."+pkfield+" in ('"+check_per+"')";
						}else{
							sqlwhere += " and "+tableAlias+".id in ("+check_per+")";
						}
					}
				}
			}
			if(src.equalsIgnoreCase("src")){
				//屏蔽已选数据
				String excludeId=check_per;
				if(excludeId.length()==0)excludeId=check_per;
				if(excludeId.length()>0){
					if(isVirtualForm){
						sqlwhere += " and t1."+vprimarykey+" not in ("+excludeId+")";
					}else{
						if(!"".equals(pkfield)){
							check_per = check_per.replaceAll(",", "','");
							sqlwhere += " and "+tableAlias+"."+pkfield+" not in ('"+excludeId+"')";
						}else{
							sqlwhere += " and "+tableAlias+".id not in ("+excludeId+")";
						}
					}
				}
			}

			if(!hasPk){
				ListHeadBean l = new ListHeadBean(pkfieldname, BoolAttr.TRUE).setIsPrimarykey(BoolAttr.TRUE);
				l.setOldWidth("0%");
				listHeadBeanList.add(l);
			}
			ListHeadBean l = new ListHeadBean(BrowserConstant.BROWSER_LIST_CHECKBOX_FIELDNAME,BoolAttr.TRUE);
			l.setOldWidth("0%");
			listHeadBeanList.add(l);

			//分页插件对字段进行排序，但这个字段必须要被查询出来，否则会报错
			if(!StringHelper.isEmpty(orderby)){
				String lowerOrderby = orderby.toLowerCase();
				lowerOrderby = lowerOrderby.replace(" asc", " ");
				lowerOrderby = lowerOrderby.replace(" desc", " ");
				String[] arr = lowerOrderby.split(",");
				arr = lowerOrderby.split(",");
				for (int j = 0; j < arr.length; j++) {
					String item = arr[j].trim();
					if(!StringHelper.isEmpty(item)){
						if(backfields.toLowerCase().indexOf(item)==-1){
							backfields += ","+item;
						}
					}
				}
			}

			SplitPageParaBean spp = new SplitPageParaBean();
			//   	System.out.println("select "+backfields+fromSql+sqlwhere);
			spp.setBackFields(backfields);
			spp.setSqlFrom(fromSql);

			if(!"".equals(treeid)){//如果是组合查询那边来的
				sqlwhere=BrowserLikeUtil.runSqlBeforePro(sqlwhere);
			}





			//支持密级参数过滤
			if(browserModeid!=-1 && (!isVirtualForm)){
				//添加密级(如果关联的模块开启了分级保护则添加密级限制)，虚拟表单不支持分级保护
				if(sqlwhere.indexOf("t1.seclvel")==-1 ){
					AddSeclevelUtil addSeclevelUtil = new AddSeclevelUtil();
					Map<String, Object> paramForsqlWhere = new HashMap<>();
					paramForsqlWhere.put("modeId", browserModeid);
					paramForsqlWhere.put("secretLevel", secretLevel);
					paramForsqlWhere.put("user", user);
					String secLevelSqlWhere =addSeclevelUtil.getBrowserOrSearchSecLevelSqlWhere(paramForsqlWhere);
					if(!"".equals(secLevelSqlWhere)){
						sqlwhere+= secLevelSqlWhere;
					}
				}
			}


			spp.setSqlWhere(sqlwhere);
			spp.setSqlOrderBy(orderby);
			spp.setPrimaryKey("hiddenfield");
			spp.setCountField(sqlprimarykey);
			spp.setPoolname(vdatasource);
			spp.setDistinct(false);
			spp.setSortWay(spp.DESC);
			SplitPageUtil spu = new SplitPageUtil();
			spu.setSpp(spp);

			if(!("1".equals(nodataloading) && !"1".equals(isFromAdvanceSearch))){
				if(!check_per.equals("")) {
					pageindex = 1;
					pagesize = 10000;
				}
				// CHANGE START
				if (ShardingActionHelper.isModeSharding(Util.getIntValue(formmodeid))) {
					int offset = ShardingActionHelper.getQueryFieldOffset(new RecordSet().getDBType());
					Map<String, String> map = new HashMap<>();
					map.put(ShardingCacheBean.SQL_BACK_FIELDS, backfields);
					map.put(ShardingCacheBean.SQL_FROM, fromSql);
					map.put(ShardingCacheBean.SQL_FIELD_OFFSET, String.valueOf(offset));
					map.put(ShardingCacheBean.SQL_ORDERBY, orderby);
					map.put(ShardingCacheBean.VAR_MODEID, formmodeid);
					ShardingCacheBean cacheBean = new ShardingCacheBean(modeId,map);
					try (HintManager hintManager = HintManager.getInstance()) {
						cacheBean.setHintValue();
						hintManager.setShardingCacheBean(cacheBean);
						RecordSetCounts = spu.getRecordCount();
					}
					if (RecordSetCounts > 0) {
						// 更新分页
						Limit limit = new Limit(true);
						limit.setRowCount(new LimitValue(pagesize, -1));
						limit.setOffset(new LimitValue((pageindex-1)*pagesize, -1));
						cacheBean.setLimit(limit);
						try (HintManager hintManager = HintManager.getInstance()) {
							cacheBean.setHintValue();
							hintManager.setShardingCacheBean(cacheBean);
							rs = spu.getCurrentPageRs(pageindex, pagesize);
						}
					}
				} else {
					rs = spu.getCurrentPageRs(1, 10000);
				}

				RecordSetCounts = spu.getRecordCount();
				// CHANGE END

				int totalPage = RecordSetCounts/pagesize;
				if(totalPage%pagesize>0||totalPage==0){
					totalPage++;
				}

				while(rs.next()) {
					Map tmp = new HashMap();

					String id = "";
					if(!isVirtualForm){
						if(!"".equals(pkfield)){
							id=rs.getString(vprimarykey);
							id = Util.toHtmlForSplitPage(id);
						}else{
							id=rs.getString(isModeSharding ? ShardingHelper.KEY_FORM_BIZ_ID : "id");
						}
					}else{
						id=rs.getString(vprimarykey);
					}
					if(!showfieldMap1.containsKey(pkfieldname)){
						showfieldMap1.put(pkfieldname, "");
					}
					Iterator<Map.Entry<String,Object>> it=showfieldMap1.entrySet().iterator();
					while(it.hasNext()){
						Map.Entry<String,Object> entity=it.next();
						String fieldName=entity.getKey();
						String paraTwo=Util.null2String(entity.getValue());
						String fieldValue=Util.null2String(rs.getString(fieldName));
						String[] paraTwos=Util.splitString(paraTwo,"+");

						if(paraTwos.length>9){
							if("0".equals(paraTwos[10])){
								fieldValue=Util.null2String(rs.getString(tablename,fieldName));
							}else{
								fieldValue=Util.null2String(rs.getString(detailtable,fieldName));
							}
						}
						if(paraTwos.length>1){
							String fieldid=paraTwos[1];
							String isencrypt= modeFormFieldEncryptComInfo.getIsencrypt(fieldid);
							if("1".equals(isencrypt)){
								fieldValue=CubeCipherUitl.decrypt(fieldValue);
							}
							//对于虚拟表单，实际表字段加密了，但是虚拟表没有设置字段加密，上面的逻辑检测不到
							if(isVirtualForm && fieldValue.startsWith("cube~cipher~start")){
								fieldValue=CubeCipherUitl.decrypt(fieldValue);
							}
						}
						if(paraTwo.length()>0&&!"".equals(pkfield)){
							paraTwo+="+"+pkfield;
							if(titleviewtype.equals("1")){
								paraTwo+="+"+detailtable;
							}
						}
						if("modedatacreatedate".equals(fieldName)){
							fieldValue=FormModeTransMethod.getSearchResultCreateTime(fieldValue,rs.getString(paraTwo));
						}else if("modedatacreater".equals(fieldName)){
							fieldValue=FormModeTransMethod.getSearchResultName(fieldValue, rs.getString(paraTwo));
						}else if("modedatamodifier".equals(fieldName)){
							fieldValue=FormModeTransMethod.getSearchResultName(fieldValue, rs.getString(paraTwo));
						}else if("modedatastatus".equals(fieldName)){
							fieldValue=cubeSearchTransMethod.getModedatastatus(fieldValue, user.getLanguage()+"");
						}else if("seclevel".equals(fieldName)){
							fieldValue=cubeSearchTransMethod.getSeclevelLable(fieldValue, user.getLanguage()+"");
						}else{
							fieldValue = Util.formatMultiLang(fieldValue, user.getLanguage()+"");
							if(id.contains("+")){
								id = id.replace("+", "{weaver}");
							}
							// CHANGE START
							Set<String> skipFields = new HashSet<>();
							skipFields.add(pkfieldname);
							skipFields.add("id");
							skipFields.add(ShardingHelper.KEY_FORM_BIZ_ID);
							skipFields.add(ShardingHelper.KEY_DETAIL_BIZ_ID);
							if(!skipFields.contains(fieldName.toLowerCase())){//QC 714955,当该字段为主键时，不获得自定义显示字段的显示内容
								fieldValue=getBrowserOthers(fieldValue, paraTwo.replaceFirst("column:id", id));
							}
							// CHANGE END
						}
						if(fieldName.equalsIgnoreCase(BrowserConstant.BROWSER_LIST_CHECKBOX_FIELDNAME)){//checkbox用
							fieldValue=	Util.null2String(rs.getString(pkfieldname));
						}
						if (!"".equals(treeid)&&(fieldName.equals(pkfieldname)||fieldName.equalsIgnoreCase(BrowserConstant.BROWSER_LIST_CHECKBOX_FIELDNAME))) {
							fieldValue=treeid+"_"+fieldValue;
						}
						if (this.isMobile) {//移动端去掉链接
							//title内容带有>，会导致匹配结果不正确，先把title去除再正则匹配
							fieldValue=fieldValue.replaceAll("title=['\"].+?['\"]\\s+","");
							fieldValue=fieldValue.replaceAll("<a .+?>(.*?)</a>", "$1");
						}
						//#1915725 概述：带<>括号的浏览框数据不显示  单独处理pc端。
						if(!this.isMobile){
							if(fieldValue.indexOf("<")>-1&&fieldValue.indexOf(">")>-1
									&&fieldValue.indexOf("<a")<0&&fieldValue.indexOf("a>")<0
									&&fieldValue.indexOf("<div")<0&&fieldValue.indexOf("div>")<0
									&&fieldValue.indexOf("<span")<0&&fieldValue.indexOf("span>")<0){
								fieldValue = fieldValue.replaceAll("<","&lt;");
								fieldValue = fieldValue.replaceAll(">","&gt;");
							}
						}
						tmp.put(fieldName,fieldValue);

					}
					data.add(tmp);
				}
			}

			if("dest".equalsIgnoreCase(src)&&!check_per.contains("+")){
				//ComparatorUtil.sortJSONArrayByKeyss(jsonArr,"id",check_per);
			}
			sql="select id,icon,iconColor,iconBg from modetreefield where id in (select appid from mode_custombrowser where id=?)";
			rs.executeQuery(sql, customid);
			Map<String, String> iconSetting = new HashMap<String, String>();
			String icon="";
			String iconColor="";
			String iconBg="";
			if(rs.next()) {
				icon = Util.null2String(rs.getString("icon"));
				iconColor = Util.null2String(rs.getString("iconColor"));
				iconBg = Util.null2String(rs.getString("iconBg"));
			}
			iconSetting.put("icon", "".equals(icon)?"icon-coms-ModelingEngine":icon);
			iconSetting.put("fontColor", "".equals(iconColor)?"#fff":iconColor);
			iconSetting.put("bgColor","".equals(iconBg)?"#96358a":iconBg );
			apidatas.put("iconSetting", iconSetting);
			if (this.isMobile) {//移动端
				apidatas.put("mobileshowtemplate", this.getMobileshowtemplate(browsertype,customid));
				apidatas.put("mobileshowtype", "listview");
			}
		}
		//------------------------------分割线-----------------------------

		apidatas.put(BrowserConstant.BROWSER_RESULT_COLUMN, listHeadBeanList);
		apidatas.put(BrowserConstant.BROWSER_RESULT_DATA, data);
		apidatas.put(BrowserConstant.BROWSER_RESULT_TYPE, BrowserDataType.LIST_SPLIT_DATA_O.getTypeid());
		apidatas.put(BrowserConstant.BROWSER_RESULT_TOTAL, RecordSetCounts);
		apidatas.put(BrowserConstant.BROWSER_RESULT_PAGESIZE, pagesize);
		return apidatas;
	}
	private String getRoleLimitedRightsql(String modeid, List<User> lsUser,String formId){
		String roleLimitedRightsql = "";
		RecordSet rs  = new RecordSet();
		String tablename="modeDataShare_"+modeid+"_set";
		String sql = "select * from "+tablename+" where sharetype=4 and isrolelimited=1 ";
		rs.executeQuery(sql);
		ModeRightForPage modeRightForPage = new ModeRightForPage();
		Set<String> rightids = new HashSet<String>();
		while(rs.next()){
			String rightid = Util.null2String(rs.getString("id"));
			String sourceid = Util.null2String(rs.getString("sourceid"));
			String content = Util.null2String(rs.getString("relatedid"));
			String showlevelValue = Util.null2String(rs.getString("showlevel"));
			String rolelevelValue = Util.null2String(rs.getString("rolelevel"));
			String showlevel2 = Util.null2String(rs.getString("showlevel2"));
			int rolefieldtype=Util.getIntValue(rs.getString("rolefieldtype"));
			//int righttype=Util.getIntValue(rs.getString("righttype"));
			String rolefield=Util.null2String(rs.getString("rolefield"));
			String hrmCompanyVirtualType = Util.null2String(rs.getString("hrmCompanyVirtualType"));
			Set<String> users = modeRightForPage.getRightUsersByRolelimited(sourceid,Util.getIntValue(formId,0),
					Util.getIntValue(content),Util.getIntValue(showlevelValue),Util.getIntValue(rolelevelValue),showlevel2,
					rolefieldtype,rolefield,hrmCompanyVirtualType);
			for(User user : lsUser){
				if(users.contains(user.getUID()+"")){
					rightids.add(rightid);
					break;
				}
			}
		}
		if(rightids.size()>0){
			roleLimitedRightsql = "(select sourceid,MAX(righttype) as sharelevel from "+tablename+" where id in("+String.join(",",rightids)+") GROUP BY sourceid)";
		}
		return roleLimitedRightsql;
	}
	/**
	 * 获取移动端展示模板
	 * @param browsertype 浏览框标识
	 * @return
	 */
	private JSONObject getMobileshowtemplate(String browsertype,String customid) {
		JSONObject obj = new JSONObject();
		JSONObject mobileLayout = CubeBrowserMobileLayoutManager.getInstance().getBrowserMobileLayout(browsertype);
		if ("".equals(mobileLayout)) {
			return obj;
		}
		StringBuilder template =new StringBuilder();
		JSONObject titlefield = (JSONObject) mobileLayout.get("titlefield");
		if (titlefield==null) {
			return obj;
		}
		RecordSet rs = new RecordSet();
		Map<String, Map<String, String>> fieldmap = new HashMap<String, Map<String,String>>();
		String sql="select w.id,w.fieldname,w.viewtype,w.type,w.fieldhtmltype from mode_custombrowserdspfield c  left join workflow_billfield w on w.id=c.fieldid where customid=? and w.id is not null";
		rs.executeQuery(sql, customid);
		while (rs.next()) {
			Map<String, String> map = new HashMap<String, String>();
			String fieldid = Util.null2String(rs.getString("id"));
			String fieldname = Util.null2String(rs.getString("fieldname"));
			String type = Util.null2String(rs.getString("type"));
			String fieldhtmltype = Util.null2String(rs.getString("fieldhtmltype"));
			String viewtype = Util.null2String(rs.getString("viewtype"));
			if ("1".equals(viewtype)) {
				fieldname="d_"+fieldname;
			}
			map.put("fieldid", fieldid);
			map.put("fieldname", fieldname);
			map.put("type", type);
			map.put("htmltype", fieldhtmltype);
			fieldmap.put(fieldid, map);
		}
		if(isImgSearch){//图片列表
			StringBuilder imgHtml = new StringBuilder();
			StringBuilder titleHtml = new StringBuilder();
			StringBuilder otherFieldHtml = new StringBuilder();
			this.handFiledForImg(titleHtml, titlefield, fieldmap, "1");
			JSONObject imgfield= mobileLayout.getJSONObject("imgfield");
			//if(imgField.equalsIgnoreCase(imgfield.getString("fieldid"))){
			if (imgfield!=null) {
				this.handFiledForImg(imgHtml, imgfield, fieldmap,"0");
			}
			//}
			JSONArray otherfields= mobileLayout.getJSONArray("otherfields");
			String css="overflow:hidden;white-space:nowrap;text-overflow:ellipsis";
			if (otherfields!=null) {
				for (Object object : otherfields) {
					JSONArray rowdata = (JSONArray) object;
					if (rowdata==null) {
						continue;
					}
					otherFieldHtml.append("<div style=\""+css+"\">");
					for (Object b : rowdata) {
						JSONObject col = (JSONObject) b;
						//String fieldid = col.getString("fieldid");
						this.handFiledForImg(otherFieldHtml, col, fieldmap,"2");

					}
					otherFieldHtml.append("</div>");
				}
			}
			template.append("<div class=\"cube-mobile-broswer-forImg\" style=\"display: flex;padding: 18px 9px 18px 9px\"><div  class=\"cube-mobile-broswer-imgDiv\" style=\"width: 40%;max-height: 120px;margin-right: 9px;min-height: 100px;height:100%;background-color: gray;\">")
					.append(imgHtml.toString())
					.append("</div><div style=\"width: 60%;padding: 5px 0;font-size: 12px;\">")
					.append(titleHtml.toString())
					.append(otherFieldHtml.toString())
					.append("</div></div>");
		}else{
			String css="overflow:hidden;white-space:nowrap;text-overflow:ellipsis";
			template.append("<div  style=\""+css+"\"");
			this.handFiled(template, titlefield, fieldmap);
			template.append("</div>");
			JSONArray otherfields= mobileLayout.getJSONArray("otherfields");
			if (otherfields!=null) {
				for (Object object : otherfields) {
					JSONArray rowdata = (JSONArray) object;
					if (rowdata==null) {
						continue;
					}
					template.append("<div style=\""+css+"\">");
					for (Object b : rowdata) {
						JSONObject col = (JSONObject) b;
						this.handFiled(template, col, fieldmap);
					}
					template.append("</div>");
				}
			}
		}
		obj.put("template", template.toString());
		return obj;
	}


	/**
	 * 处理单个字段,将其拼接成标准的string模板
	 * @param template
	 * @param field
	 * @return
	 */
	private void handFiled(StringBuilder template,JSONObject field,Map<String, Map<String, String>> fieldmap){
		String fielddesc = field.getString("fielddesc");
		String fieldid = field.getString("fieldid");
		if ("-1".equals(fieldid)) {//输入的是html
			fielddesc=fielddesc.replaceAll("\\{([a-zA-Z0-9_]+?)\\}", "#{$1}");
			template.append("<div  style=\"padding:0 10px 0 0;display:table-cell;white-space:normal;word-break:break-all\">").append(fielddesc).append("</div>");
		}else {
			Map<String, String> map = fieldmap.get(fieldid);
			if (map!=null) {
				String fieldname=map.get("fieldname");
				String type=map.get("type");
				String htmltype=map.get("htmltype");
				if ("6".equals(htmltype)&&"2".equals(type)) {//附件上传图片特殊处理
					template.append("<div  style=\"padding:0 10px 0 0;display:table-cell;white-space:normal;word-break:normal\">");
					template.append("<div style=\"white-space:normal;\">");
					template.append("#{").append(fieldname).append("}");
					template.append("</div></div>");
				}else {
					template.append("<div  style=\"padding:0 10px 0 0;display:table-cell;white-space:normal;word-break:break-all\">").append("#{").append(fieldname).append("}").append("</div>");
				}
			}
		}
	}

	/**
	 * 相册列表处理单个字段,将其拼接成标准的string模板
	 * @param template
	 * @param field
	 * @param fieldmap
	 * @param tempType 0图片 1标题 2其他字段
	 * @return
	 */
	private void handFiledForImg(StringBuilder template,JSONObject field,Map<String, Map<String, String>> fieldmap, String tempType){
		String fielddesc = field.getString("fielddesc");
		String fieldid = field.getString("fieldid");
		String css="overflow:hidden;white-space:nowrap;text-overflow:ellipsis";
		Map<String, String> map = fieldmap.get(fieldid);
		if (map!=null) {
			String fieldname = map.get("fieldname");
			String type = map.get("type");
			String htmltype = map.get("htmltype");
			if("0".equals(tempType)){
				template.append("#{").append(fieldname).append("}");
			}else if("1".equals(tempType)){
				if ("1".equals(htmltype)) {//只有文本可以作为标题，其他字段作为普通字段处理
					template.append("<div style=\""+css+";font-weight: bold;font-size:14px;height:20px\">");
					template.append("#{").append(fieldname).append("}");
					template.append("</div>");
				}else {
					if (("6".equals(htmltype)&&"2".equals(type)) || "2".equals(htmltype) || "7".equals(htmltype)) {//附件上传图片其他字段不展示

					}else {
						template.append("<div style=\""+css+";font-weight: bold;height:20px\">");
						template.append("</div>");
						template.append("<div  style=\""+css+";color:#666\">").append("#{").append(fieldname).append("}").append("</div>");
					}
				}
			}else if("2".equals(tempType)){
				if ("-1".equals(fieldid)) {//输入的是html
					fielddesc=fielddesc.replaceAll("\\{([a-zA-Z0-9_]+?)\\}", "#{$1}");
					template.append("<div  style=\"padding:0 10px 0 0;display:table-cell;white-space:normal;word-break:break-all\">").append(fielddesc).append("</div>");
				}else {
					if ("6".equals(htmltype)&&"2".equals(type)) {//附件上传图片特殊处理
						template.append("<div  style=\"padding:0 10px 0 0;display:table-cell;white-space:normal;word-break:normal\">");
						template.append("<div style=\"white-space:normal;\">");
						template.append("#{").append(fieldname).append("}");
						template.append("</div></div>");
					}else if("2".equals(htmltype)){ //多文本不显示
						template.append("<div  style=\"padding:0 10px 0 0;display:table-cell;white-space:normal;word-break:break-all\">").append("</div>");
					}else{
						template.append("<div  style=\"padding:0 10px 0 0;display:table-cell;white-space:normal;word-break:break-all\">").append("#{").append(fieldname).append("}").append("</div>");
					}
				}
			}
		}else if(fielddesc!=""&&"-1".equals(fieldid)){
			fielddesc=fielddesc.replaceAll("\\{([a-zA-Z0-9_]+?)\\}", "#{$1}");
			template.append("<div  style=\"padding:0 10px 0 0;display:table-cell;white-space:normal;word-break:break-all\">").append(fielddesc).append("</div>");
		}
	}

	/**
	 * 获得自定义显示字段的显示内容
	 * @param paraTwo  字段ID+"+"+字段类型+"+"+字段类型+"+"+显示语言
	 * @return 显示内容
	 */
	public String getBrowserOthers (String fieldvalue,String paraTwo) {
		String returnStr = "";
		try {
			CustomerInfoComInfo cci = new CustomerInfoComInfo();
			ResourceComInfo rc = new ResourceComInfo();
			DocComInfo DocComInfo1 = new DocComInfo();
			ProjectInfoComInfo ProjectInfoComInfo1 = new ProjectInfoComInfo();
			BrowserComInfo BrowserComInfo = new BrowserComInfo();
			DepartmentComInfo DepartmentComInfo1 = new DepartmentComInfo();
			SubCompanyComInfo SubCompanyComInfo1 = new SubCompanyComInfo();
			DocImageManager DocImageManager = new DocImageManager();
			WorkflowRequestComInfo WorkflowRequestComInfo1 = new WorkflowRequestComInfo();
			CapitalComInfo CapitalComInfo1 = new CapitalComInfo();
			ResourceConditionManager rcm = new ResourceConditionManager();
			DocReceiveUnitComInfo duc = new DocReceiveUnitComInfo();
			XssUtil xssUtil = new XssUtil();
			RecordSet rs = new RecordSet();
			RecordSet RecordSet = new RecordSet();
			String sql = "";
			String[] tempStr = Util.TokenizerString2(paraTwo, "+");
			if(tempStr.length==0){
				return fieldvalue;
			}
			String fieldid = Util.null2String(tempStr[1]);
			String fieldhtmltype = Util.null2String(tempStr[2]);
			String fieldtype = Util.null2String(tempStr[3]);
			int userlanguage = Util.getIntValue(Util.null2String(tempStr[4]));
			String modedataid = Util.null2String(Util.StringReplace(tempStr[0],"{weaver}", "+"));
			char flag = Util.getSeparator();
			String isbill = Util.null2String(tempStr[5]);
			String dbtype = Util.null2String(tempStr[6]);
			String istitle = Util.null2String(tempStr[7]);
			String formmodeid = Util.null2String(tempStr[8]);
			String formID = Util.null2String(tempStr[9]);
			String viewtype = Util.null2String(tempStr[10]);
			String pkfield = "id";
			String detailtable = "";
			if(tempStr.length>14){
				pkfield = Util.null2String(tempStr[14]).replace(" ", "");
			}
			if(tempStr.length>15){
				detailtable = Util.null2String(tempStr[15]);
			}
			boolean isVirtualForm = VirtualFormHandler.isVirtualForm(formID);
			String vdatasource = "";
			String vformtype="";
			String vsql="";
			if(isVirtualForm){
				Map<String,Object> vFormInfo = VirtualFormHandler.getVFormInfo(formID);
				vdatasource = Util.null2String(vFormInfo.get("vdatasource"));
				vformtype = Util.null2String(vFormInfo.get("vformtype"));
				vsql = Util.null2String(vFormInfo.get("vsql"));
				if(pkfield.equals("")){
					pkfield = Util.null2String(vFormInfo.get("vprimarykey"));	//主键列名称
				}
			}
			RecordSet recordSet = new RecordSet();
			int opentype = 0;
			int customid = 0;
			String showmethod = "";
			String viewfrom = "";//来源
			if(formmodeid.equals("0")){
				//String sqlStr = "select formmodeid from formtable_main_"+formID.replace("-", "")+" where id="+modedataid;
				String tablename = "";
				String sqlStr = "select tablename from workflow_bill where id="+formID;
				RecordSet.executeSql(sqlStr);
				if (RecordSet.next()) {
					tablename = Util.null2String(RecordSet.getString("tablename"));
				}
				if(isVirtualForm){
					if("2".equals(vformtype)){
						tablename="("+vsql+")";
					}else{
						tablename = VirtualFormHandler.getRealFromName(tablename);
					}
				}

				if (!StringHelper.isEmpty(tablename)) {
					sqlStr = "select * from "+tablename+" a where "+pkfield+"=?";
					RecordSet.executeQuery(sqlStr,modedataid);
					if(RecordSet.next()){
						formmodeid = Util.null2String(RecordSet.getString("formmodeid"),"0");
					}
				}
			}else if(formmodeid.equals("virtual")){
				formmodeid = "0";
			}
			if(tempStr.length>12){
				opentype = Util.getIntValue(tempStr[11],0);
				customid = Util.getIntValue(tempStr[12],0);
			}
			if(tempStr.length>13){
				viewfrom = Util.null2String(tempStr[13]);
			}
			if(tempStr.length>14){
				showmethod = Util.null2String(tempStr[14]);
			}
			try{
				if (fieldtype.equals("118")) {
					returnStr="<a href=\'/meeting/report/MeetingRoomPlan.jsp\' target=\'_blank\'>"+SystemEnv.getHtmlLabelName(2193,userlanguage)+"</a>";
				}
				if(fieldhtmltype.equals("1") || fieldhtmltype.equals("2") ){  // 单行,多行文本框
					if(fieldhtmltype.equals("1") && fieldtype.equals("4")){
						returnStr= Util.toDecimalDigits(fieldvalue,2);
					}else if(fieldhtmltype.equals("2")&& fieldtype.equals("2")) {
						returnStr = fieldvalue.replaceAll("(<script[^>]*?>)(.*)(</script>)", "");
					} else if(fieldtype.equals("3") && dbtype.indexOf(",") > -1){ //QC：504879
						int decimaldigits_t = Util.getIntValue(dbtype.substring(dbtype.indexOf(",") + 1, dbtype.length() -1 ), 2);
						BigDecimal b=new BigDecimal(fieldvalue);
						b.setScale(decimaldigits_t,BigDecimal.ROUND_HALF_UP);
						returnStr = Util.toDecimalDigits(b.toPlainString(), decimaldigits_t);
					}else if (fieldtype.equals("5")) {//千分位保留几位小数以qfws为准
						int decimaldigits_t = 2;
						try{
							int qfwsTrue = fieldvalue.split("\\.")[1].length();
							decimaldigits_t = qfwsTrue>0 && qfwsTrue<=4 ? qfwsTrue:2;
						}catch (Exception e){
						}
						BigDecimal b=new BigDecimal(fieldvalue);
						b.setScale(decimaldigits_t,BigDecimal.ROUND_HALF_UP);
						returnStr = Util.toDecimalDigits(b.toPlainString(), decimaldigits_t);
						//如果是千分位
						returnStr = fieldtype.equals("5")?changeToThousands(returnStr):returnStr;
						fieldvalue = returnStr;

					}else{
						returnStr=  toHtmlSearch(fieldvalue);
						/*returnStr = returnStr.replaceAll("<", "&lt;");
	        			returnStr = returnStr.replaceAll(">", "&gt;");*/
					}

				}                                                         // 单行,多行文本框条件结束
				else if(fieldhtmltype.equals("3")){                         // 浏览按钮 (涉及workflow_broswerurl表)
					if(fieldtype.equals("2") || fieldtype.equals("19") || fieldtype.equals("402") || fieldtype.equals("403")){    // 日期和时间
						returnStr=fieldvalue;
					} else if(fieldtype.equals("290")){//时间日期
						returnStr=fieldvalue;
						// returnStr="".equals(Util.null2String(fieldvalue))?"":new DateTransformer().getLocaleDateTime(fieldvalue);;
					} else if(fieldtype.equals("224")||fieldtype.equals("225") ||fieldtype.equals("226")||fieldtype.equals("227")){
						returnStr=fieldvalue;
					} else if(!fieldvalue.equals("")) {
						String url=BrowserComInfo.getBrowserurl(fieldtype);     // 浏览按钮弹出页面的url
////		                String linkurl=BrowserComInfo.getLinkurl(fieldtype);    // 浏览值点击的时候链接的url
//						EcoNineBrowserComInfo ecoNineBrowserComInfo = new EcoNineBrowserComInfo();
//		                String linkurl= ecoNineBrowserComInfo.getLinkurl(fieldtype);    // 浏览值点击的时候链接的url
						String linkurl=CubeSearchTransMethod.getBrowserLinkurl(fieldtype);    // 浏览值点击的时候链接的url
						String showname = "";                                                   // 值显示的名称
						String showid = "";                                                     // 值

						ArrayList tempshowidlist=Util.TokenizerString(fieldvalue,",");
						if(fieldtype.equals("8") || fieldtype.equals("135")){
							//项目，多项目
							for(int k=0;k<tempshowidlist.size();k++){
								if(!linkurl.equals("") ){
									showname+="<a href=javascript:window.open(\'"+linkurl+tempshowidlist.get(k)+"\') >"+ProjectInfoComInfo1.getProjectInfoname((String)tempshowidlist.get(k))+"</a>&nbsp;";
								}else{
									showname+=ProjectInfoComInfo1.getProjectInfoname((String)tempshowidlist.get(k))+" ";
								}
							}
						}else if(fieldtype.equals("1") ||fieldtype.equals("17")){
							//人员，多人员
							for(int k=0;k<tempshowidlist.size();k++){
								if(!linkurl.equals("") ){
									if("/hrm/resource/HrmResource.jsp?id=".equals(linkurl))
									{
										showname+="<a href='javaScript:openhrm("+tempshowidlist.get(k)+");' onclick='pointerXY(event);'>"+rc.getResourcename((String)tempshowidlist.get(k))+"</a>&nbsp;";
									}
									else
										showname+="<a href=javascript:window.open(\'"+linkurl+tempshowidlist.get(k)+"\') >"+rc.getResourcename((String)tempshowidlist.get(k))+"</a>&nbsp;";
								}else{
									showname+=rc.getResourcename((String)tempshowidlist.get(k))+" ";
								}
							}
						}else if(fieldtype.equals("7") || fieldtype.equals("18")){
							//客户，多客户
							for(int k=0;k<tempshowidlist.size();k++){
								if(!linkurl.equals("") ){
									showname+="<a href=javascript:window.open(\'"+linkurl+tempshowidlist.get(k)+"\') >"+cci.getCustomerInfoname((String)tempshowidlist.get(k))+"</a>&nbsp;";
								}else{
									showname+=cci.getCustomerInfoname((String)tempshowidlist.get(k))+" ";
								}
							}
						}else if ("164".equals(fieldtype) || "194".equals(fieldtype) || "169".equals(fieldtype) || "170".equals(fieldtype)) {
							// 分部，多分部
							OrganizationShowSetBiz orgShowBiz = new OrganizationShowSetBiz();
							for(int k=0;k<tempshowidlist.size();k++){
								if(!linkurl.equals("") ){
									//showname+="<a href=\'"+linkurl+tempshowidlist.get(k)+"\' target=\'_new\'>"+orgShowBiz.getSubcompanyShow("model", (String)tempshowidlist.get(k))+"</a>&nbsp;";
									showname+="<a href=javascript:window.open(\'"+linkurl+tempshowidlist.get(k)+"\') >"+orgShowBiz.getSubcompanyShow("model", (String)tempshowidlist.get(k))+"</a>&nbsp;";
								}else{
									showname+=orgShowBiz.getSubcompanyShow("model", (String)tempshowidlist.get(k))+" ";
								}
							}

						}else if(fieldtype.equals("4") || fieldtype.equals("57")|| "167".equals(fieldtype) || "168".equals(fieldtype)){
							//部门，多部门
							OrganizationShowSetBiz orgShowBiz = new OrganizationShowSetBiz();
							for(int k=0;k<tempshowidlist.size();k++){
								if(!linkurl.equals("") ){
									showname+="<a href=javascript:window.open(\'"+linkurl+tempshowidlist.get(k)+"\') >"+orgShowBiz.getDepartmentShow("model", (String)tempshowidlist.get(k))+"</a>&nbsp;";
								}else{
									showname+=orgShowBiz.getDepartmentShow("model", (String)tempshowidlist.get(k))+" ";
								}
							}
						}else if(fieldtype.equals("9") || fieldtype.equals("37")){
							//文档，多文档
							for(int k=0;k<tempshowidlist.size();k++){
								if(k>0) showname+="<br>";

								{
									if(!linkurl.equals("")){
										showname+="<a href=javascript:window.open(\'"+linkurl+tempshowidlist.get(k)+"&modedataid="+modedataid+"\') >"+DocComInfo1.getDocname((String)tempshowidlist.get(k))+"</a>";
									}else{
										showname+=DocComInfo1.getDocname((String)tempshowidlist.get(k));
									}
								}
							}
						}else if(fieldtype.equals("22")){
							//报销费用类型
							FnaSystemSetComInfo fnaSystemSetComInfo = new FnaSystemSetComInfo();
							String separator = Util.null2String(fnaSystemSetComInfo.get_separator()).trim();
							int enableDispalyAll = Util.getIntValue(fnaSystemSetComInfo.get_enableDispalyAll());
							String fullName  = "";
							if(enableDispalyAll == 1){
								BudgetfeeTypeComInfo budgetfeeTypeComInfo = new BudgetfeeTypeComInfo();
								String [] valueArr = fieldvalue.split(",");
								for (String keyid : valueArr) {
									fullName = budgetfeeTypeComInfo.getSubjectFullName(keyid, separator);
									if(!linkurl.equals("") ){
										showname+="<a href=javascript:window.open(\'"+linkurl+tempshowidlist.get(Integer.parseInt(keyid))+"\') >"+fullName+"</a>&nbsp;";
									}else{
										showname+=fullName+" ";
									}
								}
							}else{
								String tablename = "";
								String sqlStrtable = "select tablename from workflow_bill where id="+formID;
								RecordSet.executeSql(sqlStrtable);
								if (RecordSet.next()) {
									tablename = Util.null2String(RecordSet.getString("tablename"));
								}
								BrowserComInfo bci = new BrowserComInfo();
								String tablenamefylx = bci.getBrowsertablename(fieldtype+""); // 浏览框对应的表,比如人力资源表
								String columnamefylx = bci.getBrowsercolumname(fieldtype+""); // 浏览框对应的表名称字段
								String keycolumnamefylx = bci.getBrowserkeycolumname(fieldtype+""); // 浏览框对应的表值字段
								String bxsql = "select " + keycolumnamefylx + "," + columnamefylx + " from " + tablenamefylx + " where " + keycolumnamefylx + " in ( " + fieldvalue + ")";
								rs.executeSql(bxsql);
								while (rs.next()) {
									String tempshowname = Util.null2String(rs.getString(2));
									if(!linkurl.equals("") ){
										showname+="<a href=javascript:window.open(\'"+linkurl+tempshowidlist.get(Util.getIntValue(rs.getString(1)))+"\') >"+tempshowname+"</a>&nbsp;";
									}else{
										showname+=tempshowname+" ";
									}
								}
							}
						}else if(fieldtype.equals("23")){
							//资产
							for(int k=0;k<tempshowidlist.size();k++){
								if(!linkurl.equals("") ){
									showname+="<a href=javascript:window.open(\'"+linkurl+tempshowidlist.get(k)+"\') >"+CapitalComInfo1.getCapitalname((String)tempshowidlist.get(k))+"</a>&nbsp;";
								}else{
									showname+=CapitalComInfo1.getCapitalname((String)tempshowidlist.get(k))+" ";
								}
							}
						}else if(fieldtype.equals("16") || fieldtype.equals("152")|| fieldtype.equals("171")){
							//相关请求
							for(int k=0;k<tempshowidlist.size();k++){
								if(k>0) showname+="<br>";
								if(!linkurl.equals("")){
									int tempnum=0;
									tempnum++;

									showname+="<a href=javascript:void(window.open(\'"+linkurl+tempshowidlist.get(k)+"&wflinkno="+tempnum+"\')) >"+WorkflowRequestComInfo1.getRequestName((String)tempshowidlist.get(k))+"</a>";
								}else{
									showname+=WorkflowRequestComInfo1.getRequestName((String)tempshowidlist.get(k));
								}
							}
						}else if(fieldtype.equals("141")){
							//人力资源条件
							showname+=rcm.getFormShowName(fieldvalue,userlanguage);
						}
						//added by alan for td:10814
						else if(fieldtype.equals("142")) {
							//收发文单位
							for(int k=0;k<tempshowidlist.size();k++){
								if(!linkurl.equals("")){
									showname += "<a href=javascript:window.open(\'"+linkurl+tempshowidlist.get(k)+"') >"+ duc.getReceiveUnitName(""+tempshowidlist.get(k))+"</a>&nbsp;";
								}else{
									showname += duc.getReceiveUnitName(""+tempshowidlist.get(k))+" ";
								}
							}
						}
						else if(fieldtype.equals("161")){//自定义单选
							showname = "";                                   // 新建时候默认值显示的名称
							String showdesc="";
							showid =fieldvalue;                                     // 新建时候默认值
							try{
								Browser browser=(Browser)StaticObj.getServiceByFullname(dbtype, Browser.class);
								BrowserBean bb=browser.searchById(showid);
								String desc=Util.null2String(bb.getDescription());
								String name=Util.null2String(bb.getName());
								//							showname="<a title='"+desc+"'>"+name+"</a>&nbsp;";
								String href=Util.null2String(bb.getHref());
								href = href.replace("/formmode/view/AddFormMode.jsp", "/spa/cube/index.html#/main/cube/card");
								if(href.equals("")){
									showname+="<span title='"+desc+"'>"+name+"</span>&nbsp;";
								}else{
									String tempcustomid = Util.null2String(browser.getCustomid());
									href = new ButtonElement().getHrefByBrowser(tempcustomid, href, showid, recordSet);
									showname+="<a title='"+desc+"' href='"+href+"' target='_blank'>"+name+"</a>&nbsp;";
								}
							}catch(Exception e){
								e.printStackTrace();
							}
						}
						else if(fieldtype.equals("162")){//自定义多选
							showname = "";                                   // 新建时候默认值显示的名称
							showid =fieldvalue;                                     // 新建时候默认值
							try{
								Browser browser=(Browser)StaticObj.getServiceByFullname(dbtype, Browser.class);
								List l=Util.TokenizerString(showid,",");
								for(int j=0;j<l.size();j++){
									String curid=(String)l.get(j);
									BrowserBean bb=browser.searchById(curid);
									String name=Util.null2String(bb.getName());
									////System.out.println("showname:"+showname);
									String desc=Util.null2String(bb.getDescription());
									//							    showname+="<a title='"+desc+"'>"+name+"</a>&nbsp;";
									String href=Util.null2String(bb.getHref());
									href = href.replace("/formmode/view/AddFormMode.jsp", "/spa/cube/index.html#/main/cube/card");
									if(href.equals("")){
										showname+="<span title='"+desc+"'>"+name+"</span>&nbsp;";
									}else{
										String tempcustomid = Util.null2String(browser.getCustomid());
										href = new ButtonElement().getHrefByBrowser(tempcustomid, href, curid, recordSet);
										showname+="<a title='"+desc+"' href='"+href+"' target='_blank'>"+name+"</a>&nbsp;";
									}
								}
							}catch(Exception e){
							}
						}else if (fieldtype.equals("256")||fieldtype.equals("257")) {//自定义树形单选
							CustomTreeUtil customTreeUtil = new CustomTreeUtil();
							showid = fieldvalue;
							showname = customTreeUtil.getTreeFieldShowName(fieldvalue,dbtype,"onlyname");

						}else{
							String tablename=BrowserComInfo.getBrowsertablename(fieldtype); //浏览框对应的表,比如人力资源表
							String columname=BrowserComInfo.getBrowsercolumname(fieldtype); //浏览框对应的表名称字段
							String keycolumname=BrowserComInfo.getBrowserkeycolumname(fieldtype);   //浏览框对应的表值字段
							fieldvalue=deleteFirstAndEndchar(fieldvalue,",");
							String[] valueArr = fieldvalue.split(",");
							HashMap <String, String> tempDataMap = new HashMap <String, String>();
							if(fieldvalue.indexOf(",")!=-1){
								sql= "select "+keycolumname+","+columname+" from "+tablename+" where "+keycolumname+" in( "+fieldvalue+")";
							}
							else {
								sql= "select "+keycolumname+","+columname+" from "+tablename+" where "+keycolumname+"="+fieldvalue;
							}
							RecordSet.executeSql(sql);
							while(RecordSet.next()){
								String tempShowid = Util.null2String(RecordSet.getString(1));
								String tempshowname = Util.null2String(RecordSet.getString(2));
								tempDataMap.put(tempShowid, tempshowname);
							}

							for (String id : valueArr) {
								if(!linkurl.equals("") ){
									showname += "<a href=javascript:window.open(\'"+linkurl+id+"\') >"+Util.toScreen(tempDataMap.get(id),userlanguage)+"</a>&nbsp;";
								}else{
									showname +=Util.toScreen(tempDataMap.get(id),userlanguage)+" ";
								}
							}// end of while
						}
						returnStr=showname;
					}
				}                                                       // 浏览按钮条件结束
				else if(fieldhtmltype.equals("4")) {                    // check框
					returnStr=fieldvalue;
					if (this.isMobile) {
						returnStr="1".equals(fieldvalue)?SystemEnv.getHtmlLabelName(163, user.getLanguage()):SystemEnv.getHtmlLabelName(30587, user.getLanguage());
					}
				}                                                       // check框条件结束
				else if(fieldhtmltype.equals("5")){                     // 选择框   select
					String[] fieldvalueArray = {};
					if(fieldtype.equals("2")) {
						fieldvalueArray = fieldvalue.split(",");
					}else {
						fieldvalueArray = new String[1];
						fieldvalueArray[0] = fieldvalue;
					}
					returnStr="";
					// 查询选择框的所有可以选择的值
					rs.executeProc("workflow_SelectItemSelectByid", "" + fieldid + flag + isbill);
					while (rs.next()) {
						String tmpselectvalue = Util.null2String(rs.getString("selectvalue"));
						String tmpselectname = Util.toScreen(rs.getString("selectname"), userlanguage);
						for (int k=0;k<fieldvalueArray.length;k++){
							String tmpvalue = Util.null2String(fieldvalueArray[k]);
							for(String temvalue1 : tmpvalue.split(",")){
								if (temvalue1.equals(tmpselectvalue)) {
									returnStr +=","+tmpselectname;
								}
							}
						}
					}
					if(returnStr.length()>0){
						returnStr=returnStr.substring(1);
					}
				}else if(fieldhtmltype.equals("6")){
					if(!fieldvalue.equals("")) {
						sql="select id,docsubject,accessorycount from docdetail where id in("+fieldvalue+") order by id asc";
						int linknum=-1;
						RecordSet.executeSql(sql);
						while(RecordSet.next()){
							linknum++;
							if(linknum>0 && !(isImgSearch && this.isMobile)) returnStr+="<br>";
							String showid = Util.null2String(RecordSet.getString(1)) ;
							String tempshowname= Util.toScreen(RecordSet.getString(2),userlanguage) ;
							int accessoryCount=RecordSet.getInt(3);

							DocImageManager.resetParameter();
							DocImageManager.setDocid(Integer.parseInt(showid));
							DocImageManager.selectDocImageInfo();

							String docImagefileid = "";
							long docImagefileSize = 0;
							String docImagefilename = "";
							String fileExtendName = "";
							int versionId = 0;
							if(DocImageManager.next()){
								docImagefileid = DocImageManager.getImagefileid();
								docImagefileSize = DocImageManager.getImageFileSize(Util.getIntValue(docImagefileid));
								docImagefilename = DocImageManager.getImagefilename();
								fileExtendName = docImagefilename.substring(docImagefilename.lastIndexOf(".")+1).toLowerCase();
								versionId = DocImageManager.getVersionId();
							}

							if(isImgSearch && this.imgField.equals(fieldid)){
								if(this.isMobile){//相册模式下移动端只展示一个图片，多图片展示不了
									if(StringHelper.isEmpty(returnStr)){
										returnStr = "<img src=\"/weaver/weaver.file.FileDownload?fileid="+docImagefileid+"&f_weaver_belongto_userid="+user.getUID()+"&f_weaver_belongto_usertype="+user.getType()+
												"&formmode_authorize=formmode_authorize&moduleid=formmode&authorizemodeId="+formmodeid+"&authorizefieldid="+fieldid+"&authorizeformmodebillId="+modedataid+"\"  style=\"width: 100%;max-height: 120px;min-height: 100px;\">";
									}
								}else{
									returnStr += "/weaver/weaver.file.FileDownload?fileid="+docImagefileid+"&f_weaver_belongto_userid="+user.getUID()+"&f_weaver_belongto_usertype="+user.getType()+
											"&formmode_authorize=formmode_authorize&moduleid=formmode&authorizemodeId="+formmodeid+"&authorizefieldid="+fieldid+"&authorizeformmodebillId="+modedataid;
								}
							}else{
								if(accessoryCount==1 && (fileExtendName.equalsIgnoreCase("xls")||fileExtendName.equalsIgnoreCase("doc")||fileExtendName.equalsIgnoreCase("pdf"))){
									returnStr+= "<a href=\"javascript:openFullWindowHaveBar(\'/docs/docs/DocDspExt.jsp?id="+showid+"&imagefileId="+docImagefileid+"&isFromAccessory=true\')\">"+docImagefilename+"</a> ";
								}else{
									if (this.isMobile&&"2".equals(fieldtype)) {
										if(isImgSearch){
											returnStr += "<img src=\"/weaver/weaver.file.FileDownload?fileid="+docImagefileid+"&f_weaver_belongto_userid="+user.getUID()+"&f_weaver_belongto_usertype="+user.getType()+
													"&formmode_authorize=formmode_authorize&moduleid=formmode&authorizemodeId="+formmodeid+"&authorizefieldid="+fieldid+"&authorizeformmodebillId="+modedataid+"\"  style=\"width: 100%;max-height: 120px;min-height: 100px;\">";
										}else{
											returnStr += "<img  style=\"margin-top:5px;margin-right:5px;width:60px;height:60px;vertical-align:middle;object-fit:cover\" src=\"/weaver/weaver.file.FileDownload?fileid="+docImagefileid+"&f_weaver_belongto_userid="+user.getUID()+"&f_weaver_belongto_usertype="+user.getType()+
													"&formmode_authorize=formmode_authorize&moduleid=formmode&authorizemodeId="+formmodeid+"&authorizefieldid="+fieldid+"&authorizeformmodebillId="+modedataid+"\">";
										}
									}else {
										returnStr+="<a href=\"javascript:openFullWindowHaveBar(\'/docs/docs/DocDsp.jsp?id="+showid+" \')\">"+tempshowname+"</a> ";
									}
								}
							}
						}
						//相册模式下，如果查不到对应的附件信息，则返回空
						RecordSet.beforFirst();
						if(!RecordSet.next() && isImgSearch){
							fieldvalue = "";
						}
					}else if(isImgSearch && this.imgField.equals(fieldid)){
						if(!StringHelper.isEmpty(imgIcon)){
							DocDownloadCheckUtil docDownloadCheckUtil = new DocDownloadCheckUtil();
							if(this.isMobile) {//相册模式下移动端只展示一个图片，多图片展示不了
								returnStr = "<img src=\"/weaver/weaver.file.FileDownload?fileid=" + docDownloadCheckUtil.checkPermission(imgIcon, null) + "&f_weaver_belongto_userid=" + user.getUID() + "&f_weaver_belongto_usertype=" + user.getType() +
										"&formmode_authorize=formmode_authorize&moduleid=formmode&authorizemodeId=" + formmodeid + "&authorizefieldid=" + fieldid + "&authorizeformmodebillId=" + modedataid + "\"  style=\"width: 100%;max-height: 120px;min-height: 100px;\">";
							}else{
								returnStr += "/weaver/weaver.file.FileDownload?fileid="+docDownloadCheckUtil.checkPermission(imgIcon, null)+"&f_weaver_belongto_userid="+user.getUID()+"&f_weaver_belongto_usertype="+user.getType()+
										"&formmode_authorize=formmode_authorize&moduleid=formmode&authorizemodeId="+formmodeid+"&authorizefieldid="+fieldid+"&authorizeformmodebillId="+modedataid;
							}
						}
					}
				}else if(fieldhtmltype.equals("8")){                     // 公共选择框   select
					// 查询选择框的所有可以选择的值
					rs.executeSql("select * from mode_selectitempagedetail where id='"+fieldvalue+"'");
					while(rs.next()){
						String tmpselectvalue = Util.null2String(rs.getString("id"));
						String tmpselectname = Util.toScreen(rs.getString("name"),userlanguage);
						if(fieldvalue.equals(tmpselectvalue)){
							returnStr=tmpselectname;
						}
					}
				}
			} catch (Exception e) {
				returnStr="";
			}
		} catch (Exception ex) {
			writeLog(ex);
		}
		if(returnStr.equals("")){
			returnStr = fieldvalue;
		}
		return returnStr;
	}

	/**
	 * 去除前后指定字符
	 * @param str
	 * @param splitstr
	 * @return
	 */
	public String deleteFirstAndEndchar(String str, String splitstr) {
		boolean needround = false;
		if (str.substring(0, splitstr.length()).equals(splitstr)) {
			str = str.substring(splitstr.length());
			needround = true;
		}
		if (str.substring(str.length() - splitstr.length()).equals(splitstr)) {
			str = str.substring(0, str.length() - splitstr.length());
			needround = true;
		}
		if (needround) {
			return deleteFirstAndEndchar(str, splitstr);
		} else {
			return str;
		}
	}

	public  String toHtmlSearch(String s){
		s = (s == null ? "" : s);
		String tempString=s;
		tempString = tempString.replaceAll("<p>","<br/>");
		tempString = tempString.replaceAll("</p>","<br/>");
		tempString = tempString.replaceAll("<script>initFlashVideo();</script>","");
		tempString = tempString.replaceAll("<br>","");
		tempString = tempString.replaceAll("\n","<br>");

		return tempString;
	}

	private Map<String,String> getWhereAndCondition(String expendattr){
		Map<String,String> result = new HashMap<String, String>();
		String str = "";
		if(expendattr.indexOf("treerootnode")!=-1){
			String[] s3 = expendattr.split("treerootnode=",-1);
			if(s3.length==2){
				String exp3= s3[1];
				str = exp3;
				result.put("treerootnode", str);
			}
		}else{
			String[] s1 = expendattr.split("sqlwhere=",-1);
			if(s1.length==2){
			}else{
				String[] s2 = expendattr.split("sqlcondition=",-1);
				if(s2.length==2){
					String exp2 = s2[1];
					String[] s2_1 = exp2.split("sqlwhere=",-1);
					if(s2_1.length==2){
						str = s2_1[0];
						result.put("sqlcondition", str);
					}else{
						str = exp2;
						result.put("sqlcondition", str);
					}
				}
			}
		}
		return result;
	}
	private Map<String,Map<String,String>> getCondition(String expendattr){
		Map<String,String> result = getWhereAndCondition(expendattr);
		Map<String,Map<String,String>> resultMap = new HashMap<String, Map<String,String>>();
		Iterator<String> it = result.keySet().iterator();
		while(it.hasNext()){
			String key = it.next();
			String sqlwhere = result.get(key);
			if("sqlcondition".equals(key)){
				String[] sws = sqlwhere.split(",");
				Map<String,String> map = new HashMap<String, String>();
				for(String sws0:sws){
					String[] sws0s = sws0.split("=");
					if(sws0s.length==2){
						String s00 = Util.null2String(sws0s[0]).trim();
						String s01 = Util.null2String(sws0s[1]).trim();
						if(s01.startsWith("'$")&&s01.endsWith("$'")){
							s01 = s01.substring(1,s01.length()-1);
						}
						if(!"".equals(s00)
								&&!"".equals(s01)&&(
								(s01.startsWith("$")&&s01.endsWith("$")))){
							s00 = s00.toLowerCase();
							map.put(s00,s01);
						}
					}
				}
				if(!map.isEmpty()){
					resultMap.put(key, map);
				}
			}
		}
		return resultMap;
	}
	/**
	 * 构造查询条件显示列
	 *
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@Override
	public Map<String, Object> getBrowserConditionInfo(Map<String, Object> params) throws Exception {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		String browsertype = Util.null2String(params.get("type"));
		String treeid = Util.null2String(params.get("treeid"));
		String modeId =Util.null2String(params.get("modeId"));
		String fieldid = Util.null2String(params.get("formmodefieldid"));
		String ismobile = Util.null2String(params.get("ismobile"));
		String bts[] = browsertype.split("\\|");
		browsertype = bts[0];
		browsertype = URLDecoder.decode(browsertype);
		if (browsertype.indexOf("browser.") != -1) {
			browsertype = browsertype.replace("browser.", "");
		}
		RecordSet recordSet = new RecordSet();
		recordSet.executeQuery("select * from workflow_browdef_field  where modeid = ? and fieldid = ?",modeId,fieldid);
		Map<String,String> conditionValueMap = new HashMap<String,String>();
		String formmodefieldid = Util.null2String(params.get("formmodefieldid"));
		String currenttime = Util.null2String(params.get("currenttime"));//当前时间
		if(!"".equals(formmodefieldid)&&recordSet.getCounts()==0){// 没有配置数据定义高级搜索条件 解析扩展属性中的sqlcondition
			RecordSet rs = new RecordSet();
			rs.executeSql("select expendattr from ModeFormFieldExtend where fieldid="+formmodefieldid);
			if(rs.next()){
				String expendattr = rs.getString(1);
				expendattr = expendattr.replace("&lt;","<");
				expendattr = expendattr.replace("&gt;",">");
				FormModeBrowserSqlwhere fbs = new FormModeBrowserSqlwhere();
				Map<String,Map<String,String>> expendMap = getCondition(expendattr);
				if(expendMap.containsKey("sqlcondition")){
					Map<String,String> map = expendMap.get("sqlcondition");
					Iterator<String> it = map.keySet().iterator();
					while(it.hasNext()){
						String key = it.next();
						String value = map.get(key);
						value = value.replaceAll("\\$", "");
						value=value.replaceAll("\\.", "_");
						String[] values = value.split("-");
						String conditionValue="";
						if(values.length>1){
							conditionValue = Util.null2String(params.get(values[0]+"_"+currenttime)) +"-"+Util.null2String(params.get(values[1]+"_"+currenttime));
						}else{
							conditionValue = Util.null2String(params.get(value+"_"+currenttime));
						}
						conditionValueMap.put(key, conditionValue);
					}
				}
			}
		}
		Map<String,String> browserMap = getBrowserInfo(browsertype);
		List<SearchConditionItem> conditions = new ArrayList<SearchConditionItem>();
		if(browserMap!=null){
			RecordSet rs = new RecordSet();
			RecordSet RecordSet = new RecordSet();
			String customid = browserMap.get("customid");
//        	if(!"".equals(treeid)){//如果是组合查询那边来的,
//        		customid = browserMap.get("id");
//        	}
			String formID = "";
			rs.execute("select a.defaultsql,a.modeid,a.customname,a.customdesc,a.formid,a.detailtable,a.searchconditiontype,a.javafilename,a.pagenumber,a.norightlist,b.detailkeyfield from mode_custombrowser a left join workflow_bill b on a.formid=b.id where a.id="+customid);
			if(rs.next()){
				formID=Util.null2String(rs.getString("formid"));
			}

			String sql = "";
			String fields = "mode_custombrowser.detailtable as browserdetailtable,workflow_billfield.detailtable as workdetailtable,mode_CustombrowserDspField.shownamelabel ,mode_CustombrowserDspField.queryorder " +
					",mode_CustombrowserDspField.requiredCon,mode_CustombrowserDspField.conditionValue,mode_CustombrowserDspField.conditionValue1,mode_CustombrowserDspField.conditionValue2"+
					",mode_CustombrowserDspField.showorder ,workflow_billfield.id as id" +
					",workflow_billfield.fieldname as name,workflow_billfield.fielddbtype as dbtype " +
					",workflow_billfield.selectitem as selectitem,workflow_billfield.linkfield as linkfield" +
					",workflow_billfield.fieldhtmltype as httype,workflow_billfield.childfieldid as childfieldid" +
					",workflow_billfield.type as type,mode_CustombrowserDspField.conditionTransition as conditionTransition" +
					",workflow_billfield.viewtype,mode_CustombrowserDspField.isquicksearch,mode_CustombrowserDspField.istitle";
			if(RecordSet.getDBType().equals("oracle")){
				fields += ",to_char(workflow_billfield.fieldlabel) as label";
			}else if(RecordSet.getDBType().equals("mysql")){
				fields += ",convert(workflow_billfield.fieldlabel , char) as label";
			}
			else if(RecordSet.getDBType().equals("postgresql")){
				fields += ",to_char(workflow_billfield.fieldlabel) as label";
			}else{
				fields += ",convert(varchar,workflow_billfield.fieldlabel) as label";
			}
			fields+=", workflow_billfield.qfws,mode_CustombrowserDspField.isquerydefaultdisplay ";
			sql = "select * from (select "+fields+" from workflow_billfield,mode_CustombrowserDspField,mode_custombrowser where mode_CustombrowserDspField.customid=mode_custombrowser.id and mode_custombrowser.id="+customid+" and mode_CustombrowserDspField.isquery='1' and workflow_billfield.billid='"+formID+"' and workflow_billfield.id=mode_CustombrowserDspField.fieldid ";
			sql+=" union select null as browserdetailtable,null as workdetailtable,shownamelabel,queryorder,requiredCon,conditionValue,conditionValue1,conditionValue2,showorder,fieldid as id,'' as name,'' as dbtype,0 as selectitem,0 as linkfield,'' as httype,0 as childfieldid,0 as type,0 as conditionTransition,0 as viewtype ,isquicksearch,mode_CustombrowserDspField.istitle,'' as label,'2' as qfws,isquerydefaultdisplay  from mode_CustombrowserDspField where isquery='1' and fieldid in(-1,-2,-3,-4,-5,-6,-7,-8,-9) and customid="+customid;
			sql+=") a order by a.queryorder,a.showorder,a.id";
			RecordSet.execute(sql);
			int i=0;
			ConditionFactory conditionFactory = new ConditionFactory(user);
			while (RecordSet.next()){
				i++;
				int viewAttr = 2;
				String name = Util.null2String(RecordSet.getString("name"));
				name=name.toLowerCase();//conditionValueMap中key已经统一转为小写,这里不转下面的判断通不过
				int label = RecordSet.getInt("label");
				int shownamelabel = Util.getIntValue(RecordSet.getString("shownamelabel"),0);
				int isquicksearch = Util.getIntValue(RecordSet.getString("isquicksearch"),0);
				int istitle = Util.getIntValue(RecordSet.getString("istitle"),0);
				if(shownamelabel!=0){
					label = shownamelabel;
				}
				String requiredCon = Util.null2String(RecordSet.getString("requiredCon"));
				String conditionValue1 = Util.null2String(RecordSet.getString("conditionValue"));
				String conditionValue2 = Util.null2String(RecordSet.getString("conditionValue1"));
				String conditionValue3 = Util.null2String(RecordSet.getString("conditionValue2"));
				//if("1".equals(requiredCon)){
				//	viewAttr = 3;
				//}
				String htmltype = RecordSet.getString("httype");
				String browserdetailtable = Util.null2String(RecordSet.getString("browserdetailtable"));
				String workdetailtable = Util.null2String(RecordSet.getString("workdetailtable"));
				//sqlcondition中浏览按钮为明细表浏览框时,使用t1和d1分别代表主表和明细表,在这里进行特殊处理,否则下面的conditionValueMap.get(name)判断不通过
				if (!"".equals(browserdetailtable)) {//如果该浏览框是明细表浏览框
					if (!"".equals(workdetailtable)) {//是明细表字段
						name="d1."+name;
					}else{//是主表字段
						name="t1."+name;
					}
				}
				String type = RecordSet.getString("type");
				String id = RecordSet.getString("id");
				String dbtype = Util.null2String(RecordSet.getString("dbtype"));
				int conditionTransition = Util.getIntValue(RecordSet.getString("conditionTransition"),0);
				if(conditionTransition == 1 && htmltype.equals("3") && type.equals("23")){
					type = "315";
					conditionTransition = 0;
				}
				int qfws=RecordSet.getInt("qfws");
				String isquerydefaultdisplay = Util.null2String(RecordSet.getString("isquerydefaultdisplay"));
				/*
				 * 初始化创建日期   -1
				 * 创建人           -2
				 */
				SearchConditionItem searchConditionItem = new SearchConditionItem();
				String namestr = "con"+id+"_value";
				String browserType = type;
				if ("0".equals(type)) browserType = "";
				String completeUrl = "javascript:getajaxurl('" + browserType + "','"+dbtype+"','"+id+"','1')";
				ConditionType conditionType = null;

				Map<String, Object> otherParams=new HashMap<String, Object>();

				if(id.equals("-1")){
					id="_3";
					name="modedatacreatedate";
					if(shownamelabel==0){
						label = 722;
					}
					htmltype="3";
					type="2";
					conditionType = ConditionType.DATE;
					String[] domKey = {namestr+"_select",namestr+"_start",namestr+"_end"};
					//conditions.add(conditionFactory.createCondition(conditionType, label,domKey));
					SearchConditionItem conditonItem = conditionFactory.createCondition(conditionType, label,domKey);
					conditonItem.setViewAttr(viewAttr);
					Map<String,String> dateMap = new HashMap<String, String>();
					if(Util.getIntValue(conditionValue1) != 6&&Util.getIntValue(conditionValue1)!=-1) {
						dateMap.put(namestr+"_select",conditionValue1);
						dateMap.put(namestr+"_start","");
						dateMap.put(namestr+"_end","");
						//conditonItem.setValue(new String []{conditionValue1,"",""});
						conditonItem.setValue(dateMap);
					} else {
						dateMap.put(namestr+"_select","6");
						dateMap.put(namestr+"_start",conditionValue2);
						dateMap.put(namestr+"_end",conditionValue3);
						//conditonItem.setValue(new String []{"6",conditionValue1,conditionValue2});
						conditonItem.setValue(dateMap);
					}
					conditonItem.setOptions(this.getDateOptions(user.getLanguage(),-1));//设置默认选项
					conditonItem.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
					conditions.add(conditonItem);
				}else if(id.equals("-2")){
					id="-2";
					name="modedatacreater";
					if(shownamelabel==0){
						label = 882;
					}
					htmltype="3";
					type="1";
					conditionType = ConditionType.BROWSER;
					//conditions.add(conditionFactory.createCondition(conditionType, label, namestr, type));
					BrowserValueInfoService browserValueInfoService = new BrowserValueInfoService();
					SearchConditionItem conditonItem = conditionFactory.createCondition(conditionType, label, namestr, type);
					ArrayList<Map<String,Object>> broList = new ArrayList<Map<String, Object>>();
					if(!"".equals(conditionValue1)&&!"0".equals(conditionValue1)&&conditionValue1.indexOf("null")<0) {
						List<BrowserValueInfo> replaceDatas;
						replaceDatas = browserValueInfoService.getBrowserValueInfo(type, dbtype, 0, conditionValue1, user.getLanguage(), "", "");
						replaceDatas = BrowserHelper.deleteEmptyReplaceDatas(replaceDatas);
						for (Object o : replaceDatas) {
							Map<String, Object> broMap = new HashMap<String, Object>();
							BrowserValueInfo browserValueInfo = (BrowserValueInfo) o;
							String ids = browserValueInfo.getId();
							String names = browserValueInfo.getName();
							broMap.put("id", ids);
							broMap.put("name", names);
							broList.add(broMap);
						}
					}
					conditonItem.getBrowserConditionParam().setReplaceDatas(broList);
					conditonItem.setViewAttr(viewAttr);
					conditonItem.getBrowserConditionParam().setViewAttr(viewAttr);
					conditonItem.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
					conditions.add(conditonItem);
				}else if(id.equals("-7")){
					id="-7";
					name="modedatamodifier";
					if(shownamelabel==0){
						label = 3002;
					}
					htmltype="3";
					type="1";
					conditionType = ConditionType.BROWSER;
					//conditions.add(conditionFactory.createCondition(conditionType, label, namestr, type));
					BrowserValueInfoService browserValueInfoService = new BrowserValueInfoService();
					SearchConditionItem conditonItem = conditionFactory.createCondition(conditionType, label, namestr, type);
					ArrayList<Map<String,Object>> broList = new ArrayList<Map<String, Object>>();
					if(!"".equals(conditionValue1)&&!"0".equals(conditionValue1)&&conditionValue1.indexOf("null")<0) {
						List<BrowserValueInfo> replaceDatas;
						replaceDatas = browserValueInfoService.getBrowserValueInfo(type, dbtype, 0, conditionValue1, user.getLanguage(), "", "");
						replaceDatas = BrowserHelper.deleteEmptyReplaceDatas(replaceDatas);
						for (Object o : replaceDatas) {
							Map<String, Object> broMap = new HashMap<String, Object>();
							BrowserValueInfo browserValueInfo = (BrowserValueInfo) o;
							String ids = browserValueInfo.getId();
							String names = browserValueInfo.getName();
							broMap.put("id", ids);
							broMap.put("name", names);
							broList.add(broMap);
						}
					}
					conditonItem.getBrowserConditionParam().setReplaceDatas(broList);
					conditonItem.setViewAttr(viewAttr);
					conditonItem.getBrowserConditionParam().setViewAttr(viewAttr);
					conditonItem.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
					conditions.add(conditonItem);
				}else if(id.equals("-8")){
					id="-8";
					name="modedatamodifydatetime";
					if(shownamelabel==0){
						label = 516915;
					}
					conditionType = ConditionType.RANGEPICKER;
					String[] domKey = {namestr+"_start",namestr+"_end"};
					Map<String,Object> dateMap = new HashMap<String, Object>();
					SearchConditionItem conditionItem = conditionFactory.createCondition(conditionType, label,domKey);
					if(Util.getIntValue(conditionValue2) > 0) {
						dateMap.put(namestr+"_start",new String []{conditionValue2,conditionValue3});
						dateMap.put(namestr+"_end","");
						conditionItem.setValue(dateMap);
					} else if(!"".equals(conditionValue2)){
						dateMap.put(namestr+"_start",new String []{conditionValue2,conditionValue3});
						conditionItem.setValue(new String []{conditionValue2,conditionValue3});
					}
					otherParams.put("showTime",true);
					otherParams.put("quickSearch",false);
					otherParams.put("format","yyyy-MM-dd HH:mm:ss");
					conditionItem.setViewAttr(viewAttr);
					conditionItem.setOtherParams(otherParams);
					conditionItem.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
					conditions.add(conditionItem);
				}else if(id.equals("-3")){
					id="-3";
					name="id";
					if(shownamelabel==0){
						label = 81287;
					}
					htmltype="1";
					type="1";
					conditionType = ConditionType.INPUT;
					//conditions.add(conditionFactory.createCondition(conditionType, label, namestr));

					SearchConditionItem conditonItem = conditionFactory.createCondition(conditionType, label, namestr);
					conditonItem.setViewAttr(viewAttr);
					conditonItem.setValue(conditionValue1);
					conditonItem.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
					conditions.add(conditonItem);
				}else if(id.equals("-5")){//草稿状态
					id="-5";
					name="con"+id+"_value";
					if(shownamelabel==0){
						label = 385992;
					}
					List<SearchConditionOption> options = new ArrayList<SearchConditionOption>();
					SearchConditionOption searchConditionOption = new SearchConditionOption();
					searchConditionOption.setKey("");
					searchConditionOption.setShowname("");
					searchConditionOption.setChilditemid(Util.splitString("",","));
					options.add(searchConditionOption);

					SearchConditionOption searchConditionOption0 = new SearchConditionOption();
					searchConditionOption0.setKey("0");
					searchConditionOption0.setShowname(SystemEnv.getHtmlLabelName(15711,user.getLanguage()));//正式
					searchConditionOption0.setChilditemid(Util.splitString("",","));
					options.add(searchConditionOption0);

					SearchConditionOption searchConditionOption1 = new SearchConditionOption();
					searchConditionOption1.setKey("1");
					searchConditionOption1.setShowname(SystemEnv.getHtmlLabelName(220,user.getLanguage()));//草稿
					searchConditionOption1.setChilditemid(Util.splitString("",","));
					options.add(searchConditionOption1);

					SearchConditionItem conditonItem =
							conditionFactory.createCondition(
									ConditionType.SELECT,
									label,
									name+",",
									options);
					conditonItem.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
					conditions.add(conditonItem);

				}else if (id.equals("-9")) {
					id="-9";
					label = 526505;//密级字段
					SearchConditionItem conditonItem= null;
					//密级修改为从人力资源那么获取
					AddSeclevelUtil addSeclevelUtil =  new AddSeclevelUtil();
					Map<String,Object> otherParam = new HashMap<>();
					otherParam.put("fieldlabel",label);
					otherParam.put("fieldname",namestr);
					otherParam.put("parentDomkey","");
					conditonItem = addSeclevelUtil.getSecLevelOptions(conditionFactory,user,otherParam);
					conditions.add(conditonItem);
				}else if("1".equals(htmltype)){//单行文本
					SearchConditionItem searchConditionItem2 = null;
					boolean quicksearch = (istitle == 1||istitle == 2) ? true : false;
	        		/*if("1".equals(Util.null2String(params.get("ismobile")))){
	        			quicksearch = (istitle == 1||istitle == 2||isquicksearch==1) ? true : false;
	        		}*/
					Map<String,Object> isMobx = new HashMap<String,Object>();
					isMobx.put("isMobx",true);
					if(type.equals("2")){//整数
						conditionType = ConditionType.SCOPE;
						searchConditionItem2 = conditionFactory.createCondition(conditionType,label,new String[]{namestr+"_start",namestr+"_end"});
						String startValue = "";
						String endValue = "";
						String conditionValueString = Util.null2String(conditionValueMap.get(name));
						if(!conditionValueMap.isEmpty()){
							String[] startAndEndValues= conditionValueString.split("-");
							if(startAndEndValues.length>1){
								startValue = startAndEndValues[0];
								endValue= startAndEndValues[1];
							}else if(startAndEndValues.length>0){
								startValue = startAndEndValues[0];
							}
						}
						if(!"".equals(startValue)){
							searchConditionItem2.setStartValue(startValue);
							searchConditionItem2.setEndValue(endValue);
						}else{
							if("".equals(conditionValue1)&&"".equals(conditionValue2)){

							}else{
								searchConditionItem2.setStartValue(conditionValue1);   //条件参数
								searchConditionItem2.setEndValue(conditionValue2);
							}
						}
						otherParams.put("step","1");
					}else if(type.equals("3")||type.equals("4")||type.equals("5")){//浮点数
						conditionType = ConditionType.SCOPE;

						int digitsIndex = dbtype.indexOf(",");
						int decimaldigits = Util.getIntValue(dbtype.substring(digitsIndex+1, dbtype.length()-1), 2);
						if("5".equals(type)){
							decimaldigits=qfws;
						}
						String step = "1";
						for(int j = 1; j<decimaldigits;j++) {
							step = "0"+step;
						}
						step = "0."+step;
						otherParams.put("step", step);
						otherParams.put("precision", decimaldigits);

						searchConditionItem2 = conditionFactory.createCondition(conditionType,label,new String[]{namestr+"_start",namestr+"_end"});
						String startValue = "";
						String endValue = "";
						String conditionValueString = Util.null2String(conditionValueMap.get(name));
						if(!conditionValueMap.isEmpty()){
							String[] startAndEndValues= conditionValueString.split("-");
							if(startAndEndValues.length>1){
								startValue = startAndEndValues[0];
								endValue= startAndEndValues[1];
							}else if(startAndEndValues.length>0){
								startValue = startAndEndValues[0];
							}
						}
						if(!"".equals(startValue)){
							searchConditionItem2.setStartValue(startValue);
							searchConditionItem2.setEndValue(endValue);
						}else{
							if("".equals(conditionValue1)&&"".equals(conditionValue2)){

							}else{
								searchConditionItem2.setStartValue(conditionValue1);   //条件参数
								searchConditionItem2.setEndValue(conditionValue2);
							}
						}
					}else{
						conditionType = ConditionType.INPUT;
						searchConditionItem2 = conditionFactory.createCondition(conditionType, label, namestr,quicksearch);
						if(!"".equals(Util.null2String(conditionValueMap.get(name)))){
							searchConditionItem2.setValue(conditionValueMap.get(name));
						}else if(!"".equals(conditionValue1)){
							searchConditionItem2.setValue(conditionValue1);
						}
					}
					searchConditionItem2.setOtherParams(otherParams);
					searchConditionItem2.setViewAttr(viewAttr);
					searchConditionItem2.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
					if(searchConditionItem2!=null){
						conditions.add(searchConditionItem2);
					}
				}else if("2".equals(htmltype)){//多行文本
					conditionType = ConditionType.INPUT;
					SearchConditionItem searchConditionItem2 = null;
					searchConditionItem2 = conditionFactory.createCondition(conditionType, label, namestr);
					if(!"".equals(Util.null2String(conditionValueMap.get(name)))){
						searchConditionItem2.setValue(conditionValueMap.get(name));
					}else if(!"".equals(conditionValue1)){
						searchConditionItem2.setValue(conditionValue1);
					}
					searchConditionItem2.setViewAttr(viewAttr);
					searchConditionItem2.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
					conditions.add(searchConditionItem2);
				}else if("3".equals(htmltype)){
					if("2".equals(type)){
						conditionType = ConditionType.DATE;
						String[] domKey = {namestr+"_select",namestr+"_start",namestr+"_end"};
						SearchConditionItem searchConditionItem2 = conditionFactory.createCondition(conditionType, label,domKey);
						searchConditionItem2.setViewAttr(viewAttr);
						Map<String,String> dateMap = new HashMap<String, String>();
						if(Util.getIntValue(conditionValue1) != 6&&Util.getIntValue(conditionValue1)!=-1) {
							dateMap.put(namestr+"_select",conditionValue1);
							dateMap.put(namestr+"_start","");
							dateMap.put(namestr+"_end","");
							//conditonItem.setValue(new String []{conditionValue1,"",""});
							searchConditionItem2.setValue(dateMap);
						} else {
							dateMap.put(namestr+"_select","6");
							dateMap.put(namestr+"_start",conditionValue2);
							dateMap.put(namestr+"_end",conditionValue3);
							//conditonItem.setValue(new String []{"6",conditionValue1,conditionValue2});
							searchConditionItem2.setValue(dateMap);
						}
						searchConditionItem2.setOptions(this.getDateOptions(user.getLanguage(),0));//设置默认选项
						searchConditionItem2.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
						conditions.add(searchConditionItem2);
					}else if("19".equals(type)){
						conditionType = ConditionType.TIMERANGEPICKER;
						String[] domKey = {namestr+"_start",namestr+"_end"};
						Map<String,Object> dateMap = new HashMap<String, Object>();
						SearchConditionItem searchConditionItem2 = conditionFactory.createCondition(conditionType, label,domKey);
						searchConditionItem2.setViewAttr(viewAttr);
						if(Util.getIntValue(conditionValue1) > 0) {
							dateMap.put(namestr+"_start",new String []{conditionValue1,conditionValue2});
							dateMap.put(namestr+"_end","");
							searchConditionItem2.setValue(dateMap);
						} else if(!"".equals(conditionValue1)){
							dateMap.put(namestr+"_start",new String []{conditionValue1,conditionValue2});
							//dateMap.put(namestr+"_end",conditionValue2);
							searchConditionItem2.setValue(new String []{conditionValue1,conditionValue2});
						}
						searchConditionItem2.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
						conditions.add(searchConditionItem2);
					}else if("290".equals(type)){
						conditionType = ConditionType.RANGEPICKER;
						String[] domKey = {namestr+"_start",namestr+"_end"};
						Map<String,Object> dateMap = new HashMap<String, Object>();
						SearchConditionItem conditionItem = conditionFactory.createCondition(conditionType, label,domKey);
						if(Util.getIntValue(conditionValue2) > 0) {
							dateMap.put(namestr+"_start",new String []{conditionValue2,conditionValue3});
							dateMap.put(namestr+"_end","");
							conditionItem.setValue(dateMap);
						} else if(!"".equals(conditionValue2)){
							dateMap.put(namestr+"_start",new String []{conditionValue2,conditionValue3});
							conditionItem.setValue(new String []{conditionValue2,conditionValue3});
						}
						otherParams.put("showTime",true);
						otherParams.put("quickSearch",false);
						otherParams.put("format","yyyy-MM-dd HH:mm:ss");
						conditionItem.setViewAttr(viewAttr);
						conditionItem.setOtherParams(otherParams);
						conditionItem.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
						conditions.add(conditionItem);
					}else if("402".equals(type)){
						conditionType = ConditionType.DATEPICKER;
						SearchConditionItem conditionItem = conditionFactory.createCondition(conditionType, label,namestr);
						//otherParams.put("showTime",true);
						otherParams.put("quickSearch",false);
						otherParams.put("noInput","true");
						if(ismobile.equals("1")){
							otherParams.put("mode","year");
						}else{
							otherParams.put("format","YYYY");
						}
						conditionItem.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
						conditionItem.setViewAttr(viewAttr);
						conditionItem.setValue(conditionValue1);
						conditionItem.setOtherParams(otherParams);
						conditions.add(conditionItem);
					}else if("403".equals(type)){
						conditionType = ConditionType.DATEPICKER;
						SearchConditionItem conditionItem = conditionFactory.createCondition(conditionType, label,namestr);
						//otherParams.put("showTime",true);
						otherParams.put("quickSearch",false);
						otherParams.put("noInput","true");
						if(ismobile.equals("1")){
							otherParams.put("mode","month");
						}else{
							otherParams.put("format","YYYY-MM");
						}
						conditionItem.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
						conditionItem.setViewAttr(viewAttr);
						conditionItem.setValue(conditionValue1);
						conditionItem.setOtherParams(otherParams);
						conditions.add(conditionItem);
					}else{
						if(type.equals("179")&&conditionTransition==1){
							type="314";
						}
						if(type.equals("25")&&conditionTransition==1){
							type="317";
						}
						conditionType = ConditionType.BROWSER;
						SearchConditionItem searchConditionItem1 = conditionFactory.createCondition(conditionType, label, namestr,type);
						if (type.equals("4") ||type.equals("57")||type.equals("164")  ||type.equals("169")||type.equals("194")|| type.equals("167")|| type.equals("170")|| type.equals("168")) {   //部门，多部门，分部，多分部，单点分权，分权单部门，分权多分部，分权多部门
							searchConditionItem1.getBrowserConditionParam().getDataParams().put("fromModule","model");
							searchConditionItem1.getBrowserConditionParam().getCompleteParams().put("fromModule","model");
							searchConditionItem1.getBrowserConditionParam().getDestDataParams().put("fromModule","model");
						}
						if(type.equals("179")){
							searchConditionItem1.getBrowserConditionParam().getOtherParams().put("hasLeftTree",false);
						}
						searchConditionItem1.getBrowserConditionParam().setViewAttr(viewAttr);
						List<BrowserValueInfo> replaceDatas;
						BrowserValueInfoService browserValueInfoService = new BrowserValueInfoService();
						ArrayList<Map<String,Object>> broList = new ArrayList<Map<String, Object>>();
						if(!"0".equals(conditionValue1)&&!"".equals(conditionValue1)&&conditionValue1.indexOf("null")<0){
							String[] conditionValue1s=conditionValue1.split(",");
							for(String value:conditionValue1s){
								replaceDatas = browserValueInfoService.getBrowserValueInfo(type,dbtype,0,value, user.getLanguage(), "","");
								replaceDatas= BrowserHelper.deleteEmptyReplaceDatas(replaceDatas);
								for (Object o : replaceDatas) {
									Map<String, Object> broMap = new HashMap<String, Object>();
									BrowserValueInfo browserValueInfo = (BrowserValueInfo) o;
									if("141".equals(type)){
										broMap = browserValueInfo.getProp();
									}else {
										String ids = browserValueInfo.getId();
										String names = browserValueInfo.getName();
										broMap.put("id", ids);
										broMap.put("name", names);
									}
									broList.add(broMap);
								}
							}
						}
						if(broList.size()>0){
							searchConditionItem1.getBrowserConditionParam().setReplaceDatas(broList);
						}
						if("161".equals(type)||"162".equals(type)||"256".equals(type)||"257".equals(type)){
							com.api.browser.bean.BrowserBean browserProp = searchConditionItem1.getBrowserConditionParam();
							browserProp.setIsMultCheckbox(true);
							browserProp.getDestDataParams().put("type", dbtype);
							String key = dbtype;
							if("161".equals(type)||"162".equals(type)){
								browserProp.setScrollx(true);
								try{
									weaver.interfaces.workflow.browser.Browser browser = (weaver.interfaces.workflow.browser.Browser) StaticObj.getServiceByFullname(key, Browser.class);
									BaseBrowser browser1 = (BaseBrowser) StaticObj.getServiceByFullname(key, Browser.class);
									List<String> fieldList  = browser.getRequestFieldMap();
									List<String> relateFieldid = new ArrayList<String>();
									Map<String,Object> dataParams  = browserProp.getDataParams();
									dataParams.put("type", key);
									dataParams.put("currenttime", System.currentTimeMillis());
									int customId = Util.getIntValue(browser.getCustomid());
									if (customId > 0) {
										ModeBrowserComInfo modeBrowserComInfo = new ModeBrowserComInfo();
										int datashowtype = Util.getIntValue(modeBrowserComInfo.getDatashowtype(customId + ""), 0);
										if(datashowtype == 1){//相册
											FormModeBrowserUtil formbrowser = new FormModeBrowserUtil();
											dataParams.put("datashowtype", formbrowser.getImgJson(browser));
										}
									}
									RecordSet rst = new RecordSet();
									rst.executeQuery("select nodataloading from mode_browser where showname=?", key.replace("browser.",""));
									if (rst.next()) {
										dataParams.put("nodataloading", Util.null2o(rst.getString("nodataloading")));
									}
									Map<String, Object> searchParams = browserProp.getSearchParams();
									searchParams.put("isFromAdvanceSearch", "1");
									Map<String,Object> completeParams = browserProp.getCompleteParams();
									completeParams.put("fielddbtype", key);
									completeParams.put("type", type);

									Map<String,Object> conditionDataParams = browserProp.getConditionDataParams();
									conditionDataParams.put("type", key);
									String href = browser.getHref();
									href = href.replace("/formmode/view/AddFormMode.jsp", "/spa/cube/index.html#/main/cube/card");

									RecordSet rsPagenumber = new RecordSet();
									String sqlPagenumber = "SELECT pagenumber FROM mode_custombrowser WHERE id = ?";
									rsPagenumber.executeQuery(sqlPagenumber,customId);
									if (rsPagenumber.next()){
										pagenumber = Integer.parseInt(Util.null2String(rsPagenumber.getString("pagenumber")));
									}
									browser1.setPageSize(pagenumber);
									browserProp.setPageSize(pagenumber);
									browserProp.setLinkUrl(href);
									browserProp.setViewAttr(viewAttr);
									browserProp.setRelateFieldid(relateFieldid);
									browserProp.setHasAdvanceSerach(!"1".equals(Util.null2String(browser.getShowtree())));
									//String sqlcustomname = "select t.customname from mode_custombrowser t where t.id=(select t1.customid from mode_browser t1 where t1.showname='"+browser.getName()+"')";//获取标示的方法是错误的，可能是改造后没有修改
									String sqlcustomname = "select t.customname from mode_custombrowser t where t.id=(select t1.customid from mode_browser t1 where t1.showname='"+browser.getShowName()+"')";//#89558概述：解决了浏览框高级搜索中的自定义浏览框点击显示的是标识，设置默认值处显示的是名称的问题
									String titlename = "";
									rs.execute(sqlcustomname);
									if(rs.next()){
										titlename = rs.getString(1);
									}
									browserProp.setTitle(titlename);
								}catch(Exception e){
									e.printStackTrace();
								}
							}else{
								BrowserInitUtil browserInitUtil = new BrowserInitUtil();
								browserProp.getDataParams().put("cube_treeid", key);
								browserProp.setType(String.valueOf(type));
								browserProp.setViewAttr(viewAttr);
								browserInitUtil.initBrowser(browserProp, user.getLanguage());
								browserProp.getDataParams().put("cube_treeid", key+"_searchType");
							}

						}
						if(!"".equals(conditionValueMap.get(name))){
							searchConditionItem1 = getBrowserDefaultValue(searchConditionItem1,Util.getIntValue(type,0),conditionValueMap.get(name));
						}
						if(BrowserHelper.isSingleBrowserField(type)&&conditionTransition==1){
							com.api.browser.bean.BrowserBean browserProp = searchConditionItem1.getBrowserConditionParam();
							if(browserProp!=null){
								browserProp.setType(BrowserHelper.convertSingleBrowserTypeToMulti(type));
								browserProp.setIsSingle(false);
								browserProp.setViewAttr(viewAttr);
								if(BrowserHelper.isMultCheckbox(type))browserProp.setIsMultCheckbox(true);
							}
							searchConditionItem1.setDomkey(new String[]{"multiselectValue_con"+id+"_value"});
						}
						searchConditionItem1.setViewAttr(viewAttr);
						searchConditionItem1.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
						conditions.add(searchConditionItem1);
					}
				}else if("4".equals(htmltype)){
	        		/*conditionType = ConditionType.CHECKBOX;
	        		SearchConditionItem searchConditionItem2  = conditionFactory.createCondition(conditionType, label, namestr);
					if(!"".equals(conditionValueMap.get(name))){
						searchConditionItem2.setValue(conditionValueMap.get(name));
					}
	        		conditions.add(searchConditionItem2);*/

					SearchConditionItem searchConditionItem1 = conditionFactory.createCondition(ConditionType.SELECT, label, namestr,this.getCheckOptions(user.getLanguage()));
					searchConditionItem1.setViewAttr(viewAttr);
					searchConditionItem1.setDetailtype(3);
					searchConditionItem1.setSupportCancel(true);
					searchConditionItem1.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
					conditions.add(searchConditionItem1);


				}else if("5".equals(htmltype)){
					conditionType = ConditionType.SELECT;
					List<SearchConditionOption> list = new ArrayList<SearchConditionOption>();
					String value = "";
					if(!"".equals(Util.null2String(conditionValueMap.get(name)))){
						value = conditionValueMap.get(name);
					}else if(!"".equals(conditionValue1)){
						value = conditionValue1;
					}

					if(conditionTransition!=1) {
						SearchConditionOption options0 = new SearchConditionOption();
						options0.setKey("");
						options0.setShowname("");
						options0.setSelected(false);
						list.add(options0);
					}

					char flag=2;
					rs.executeProc("workflow_SelectItemSelectByid",""+id+flag+"1");
					while(rs.next()){
						int tmpselectvalue = rs.getInt("selectvalue");
						String tmpselectname = rs.getString("selectname");

						String tempcancel = rs.getString("cancel");
						if("1".equals(tempcancel)){
							continue;
						}
						SearchConditionOption options = new SearchConditionOption();
						options.setKey(tmpselectvalue+"");
						options.setShowname(tmpselectname);
						if(value.indexOf(",")>-1){
							String[] SelecV = value.split(",");
							for(String v:SelecV){
								if((tmpselectvalue+"").equals(v)){
									options.setSelected(true);
								}
							}
						}else{
							options.setSelected((tmpselectvalue+"").equals(value));
						}
						list.add(options);
					}
					SearchConditionItem searchConditionItem1;
					if(conditionTransition==1) {
						otherParams.put("multiple", true);
						searchConditionItem1=conditionFactory.createCondition(conditionType, label, "multiselectValue_con"+id+"_value",list);
						searchConditionItem1.setMultiple(true);
						searchConditionItem1.setMultiSelection(true);
						searchConditionItem1.setOtherParams(otherParams);
					}else {
						if (type.equals("2")) {//选择框多选
							//otherParams.put("multiple", true);
							searchConditionItem1 = conditionFactory.createCondition(conditionType, label, "multiselectValue_con" + id + "_value", list);
							searchConditionItem1.setOtherParams(otherParams);
							searchConditionItem1.setDetailtype(2);
							searchConditionItem1.setValue(conditionValue1);
						} else if (type.equals("3")) {
							searchConditionItem1 = conditionFactory.createCondition(conditionType, label, namestr, list);
							searchConditionItem1.setDetailtype(3);
							otherParams.put("supportCancel", true);
							searchConditionItem1.setOtherParams(otherParams);
							searchConditionItem1.setValue(conditionValue1);
						} else {
							searchConditionItem1 = conditionFactory.createCondition(conditionType, label, namestr, list);
							searchConditionItem1.setValue(conditionValue1);
							searchConditionItem1.setOtherParams(otherParams);
						}
					}
					searchConditionItem1.setViewAttr(viewAttr);
					searchConditionItem1.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
					conditions.add(searchConditionItem1);
				}else if("6".equals(htmltype)){
					SearchConditionItem conditionItem = conditionFactory.createCondition(ConditionType.BROWSER, label, namestr,"9");
					conditionItem.setDefaultDisplayInBar(isquerydefaultdisplay.equals("1"));
					conditions.add(conditionItem);
				}
			}
		}
		apidatas.put(BrowserConstant.BROWSER_RESULT_CONDITIONS, conditions);
		return apidatas;
	}


	public SearchConditionItem getBrowserDefaultValue(SearchConditionItem conditionItem,int type,String value) throws Exception{

		value = Util.null2String(value);
		if ("".equals(value))
			return conditionItem;
		String[] browserValueIds = Util.splitString(value, ",");
		if (browserValueIds.length == 0) {
			return conditionItem;
		}
		List<Map<String, Object>> browserValueObjs = new ArrayList<Map<String, Object>>();
		ResourceComInfo rcomInfo = null;
		DepartmentComInfo deptComInfo = null;
		SubCompanyComInfo subCompanyComInfo = null;
		com.api.browser.bean.BrowserBean browserBean = conditionItem.getBrowserConditionParam();
		String dbtype = "";
		RecordSet RecordSet = new RecordSet();
		switch (type) {
			case 1: // 人力资源
			case 17: // 多人员
				rcomInfo = new ResourceComInfo();
				deptComInfo = new DepartmentComInfo();
				subCompanyComInfo = new SubCompanyComInfo();
				for (String resourceid : browserValueIds) {
					Map<String, Object> userInfo = new HashMap<String, Object>();
					userInfo.put("id", resourceid);
					userInfo.put("lastname", rcomInfo.getLastname(resourceid));
					userInfo.put("jobtitlename", MutilResourceBrowser.getJobTitlesname(resourceid));
					userInfo.put("icon", rcomInfo.getMessagerUrls(resourceid));
					userInfo.put("type", "resource");
					userInfo.put("departmentname", deptComInfo.getDepartmentname(rcomInfo.getDepartmentID(resourceid)));
					String subcompanyid = deptComInfo.getSubcompanyid1(rcomInfo.getDepartmentID(resourceid));
					String parentsubcompanyid = subCompanyComInfo.getSupsubcomid(subcompanyid);
					userInfo.put("subcompanyname", subCompanyComInfo.getSubcompanyname(subcompanyid));
					userInfo.put("supsubcompanyname", subCompanyComInfo.getSubcompanyname(parentsubcompanyid));
					browserValueObjs.add(userInfo);
				}
				break;
			case 4: // 部门
			case 57:
				deptComInfo = new DepartmentComInfo();
				for (String deptId : browserValueIds) {
					Map<String, Object> deptInfo = new HashMap<String, Object>();
					deptInfo.put("id", deptId);
					deptInfo.put("name", deptComInfo.getDepartmentname(deptId));
					browserValueObjs.add(deptInfo);
				}
				break;
			case 7: // 客户
			case 18: // 多客户
				CustomerInfoComInfo cusComInfo = new CustomerInfoComInfo();
				for (String cusId : browserValueIds) {
					Map<String, Object> cusInfo = new HashMap<String, Object>();
					cusInfo.put("id", cusId);
					cusInfo.put("name", cusComInfo.getCustomerInfoname(cusId));
					browserValueObjs.add(cusInfo);
				}
				break;
			case 8: //项目，多项目
			case 135:
				ProjectInfoComInfo ProjectInfoComInfo = new ProjectInfoComInfo();
				for (String cusId : browserValueIds) {
					Map<String, Object> item = new HashMap<String, Object>();
					item.put("id", cusId);
					item.put("name", ProjectInfoComInfo.getProjectInfoname(cusId));
					browserValueObjs.add(item);
				}
				break;
			case 24:
				JobComInfo jobComInfo = new JobComInfo();
				for(String jobid:browserValueIds){
					Map<String, Object> cusInfo = new HashMap<String, Object>();
					cusInfo.put("id", jobid);
					cusInfo.put("name", jobComInfo.getJobName(jobid));
					browserValueObjs.add(cusInfo);
				}
				break;
			case 58: // 城市
				CityComInfo cityComInfo = new CityComInfo();
				for (String cityId : browserValueIds) {
					Map<String, Object> cityInfo = new HashMap<String, Object>();
					cityInfo.put("id", cityId);
					cityInfo.put("name", cityComInfo.getCityname(cityId));
					browserValueObjs.add(cityInfo);
				}
				break;
			case 60: // 客户类型
				CustomerTypeComInfo cusTypeComInfo = new CustomerTypeComInfo();
				for (String cusTypeId : browserValueIds) {
					Map<String, Object> cusTypeInfo = new HashMap<String, Object>();
					cusTypeInfo.put("id", cusTypeId);
					cusTypeInfo.put("name", cusTypeComInfo.getCustomerTypename(cusTypeId));
					browserValueObjs.add(cusTypeInfo);
				}
				break;
			case 61: // 客户描述
				CustomerDescComInfo cusDescComInfo = new CustomerDescComInfo();
				for (String cusDescId : browserValueIds) {
					Map<String, Object> cusDescInfo = new HashMap<String, Object>();
					cusDescInfo.put("id", cusDescId);
					cusDescInfo.put("name", cusDescComInfo.getCustomerDescname(cusDescId));
					browserValueObjs.add(cusDescInfo);
				}
				break;
			case 62:// 客户规模
				CustomerSizeComInfo cusSizeComInfo = new CustomerSizeComInfo();
				for (String cusSizeId : browserValueIds) {
					Map<String, Object> itmInfo = new HashMap<String, Object>();
					itmInfo.put("id", cusSizeId);
					itmInfo.put("name", cusSizeComInfo.getCustomerSizename(cusSizeId));
					browserValueObjs.add(itmInfo);
				}
				break;
			case 63: // 行业
				SectorInfoComInfo sectorInfoComInfo = new SectorInfoComInfo();
				for (String sectorInfoid : browserValueIds) {
					Map<String, Object> itmInfo = new HashMap<String, Object>();
					browserValueObjs.add(itmInfo);
					itmInfo.put("id", sectorInfoid);
					itmInfo.put("name", sectorInfoComInfo.getSectorInfoname(sectorInfoid));
				}
				break;
			case 87: // 会议室
				MeetingRoomComInfo meetingRoomComInfo = new MeetingRoomComInfo();
				for (String meetingRoomId : browserValueIds) {
					Map<String, Object> meetingRoomInfo = new HashMap<String, Object>();
					meetingRoomInfo.put("id", meetingRoomId);
					meetingRoomInfo.put("name", meetingRoomComInfo.getMeetingRoomInfoname(meetingRoomId));
					browserValueObjs.add(meetingRoomInfo);
				}
				break;
			case 9://文档，多文档
			case 37:
				DocComInfo DocComInfo = new DocComInfo();
				for (String id : browserValueIds) {
					String name = DocComInfo.getDocname(id);
					Map<String, Object> item = new HashMap<String, Object>();
					item.put("id", id);
					item.put("name", name);
					browserValueObjs.add(item);
				}
				break;
			case 22://报销费用类型
				FnaSystemSetComInfo fnaSystemSetComInfo = new FnaSystemSetComInfo();
				String separator = Util.null2String(fnaSystemSetComInfo.get_separator()).trim();
				int enableDispalyAll = Util.getIntValue(fnaSystemSetComInfo.get_enableDispalyAll());

				String fullName  = "";
				if(enableDispalyAll == 1){
					BudgetfeeTypeComInfo budgetfeeTypeComInfo = new BudgetfeeTypeComInfo();
					for (String id : browserValueIds) {
						fullName = budgetfeeTypeComInfo.getSubjectFullName(id, separator);
						Map<String, Object> item = new HashMap<String, Object>();
						item.put("id", id);
						item.put("name", fullName);
						browserValueObjs.add(item);
					}
				}else{
					BrowserComInfo bci = new BrowserComInfo();
					String columname = bci.getBrowsercolumname(type+""); // 浏览框对应的表名称字段
					String keycolumname = bci.getBrowserkeycolumname(type+""); // 浏览框对应的表值字段
					String tablename= bci.getBrowsertablename(type+""); //浏览框对应的表,比如人力资源表
					String fieldvalue = StringUtils.join(browserValueIds);
					fieldvalue=deleteFirstAndEndchar(fieldvalue,",");
					String sql = "";
					if(fieldvalue.indexOf(",")!=-1){
						sql= "select "+keycolumname+","+columname+" from "+tablename+" where "+keycolumname+" in( "+fieldvalue+")";
					}
					else {
						sql= "select "+keycolumname+","+columname+" from "+tablename+" where "+keycolumname+"="+fieldvalue;
					}
					RecordSet.execute(sql);
					while(RecordSet.next()){
						Map<String, Object> item = new HashMap<String, Object>();
						item.put("id", RecordSet.getString(1));
						item.put("name", Util.toScreen(RecordSet.getString(2),user.getLanguage()));
						browserValueObjs.add(item);
					}
				}

				break;
			case 23://资产
				CapitalComInfo CapitalComInfo1 = new CapitalComInfo();
				for (String id : browserValueIds) {
					String name = CapitalComInfo1.getCapitalname(id);
					Map<String, Object> item = new HashMap<String, Object>();
					item.put("id", id);
					item.put("name", name);
					browserValueObjs.add(item);
				}
				break;
			case 16://相关请求
			case 152:
			case 171:
				WorkflowRequestComInfo WorkflowRequestComInfo1 = new WorkflowRequestComInfo();
				for (String id : browserValueIds) {
					String name = WorkflowRequestComInfo1.getRequestName(id);
					Map<String, Object> item = new HashMap<String, Object>();
					item.put("id", id);
					item.put("name", name);
					browserValueObjs.add(item);
				}
				break;
			case 141://人力资源条件
				ResourceConditionManager rcm = new ResourceConditionManager();
				for (String id : browserValueIds) {
					String name = rcm.getFormShowName(id,user.getLanguage());
					Map<String, Object> item = new HashMap<String, Object>();
					item.put("id", id);
					item.put("name", name);
					browserValueObjs.add(item);
				}
				break;
			case 142://收发文单位
				DocReceiveUnitComInfo duc = new DocReceiveUnitComInfo();
				for (String id : browserValueIds) {
					String name = duc.getReceiveUnitName(id);
					Map<String, Object> item = new HashMap<String, Object>();
					item.put("id", id);
					item.put("name", name);
					browserValueObjs.add(item);
				}
				break;
			case 164:// 分部
				subCompanyComInfo = new SubCompanyComInfo();
				for (String subId : browserValueIds) {
					Map<String, Object> subInfo = new HashMap<String, Object>();
					subInfo.put("id", subId);
					subInfo.put("name", subCompanyComInfo.getSubcompanyname(subId));
					browserValueObjs.add(subInfo);
				}
				break;
			case 244://項目类型
				ProjectTypeComInfo projectTypeComInfo = new ProjectTypeComInfo();
				for (String projectTypeId : browserValueIds) {
					Map<String, Object> itmInfo = new HashMap<String, Object>();
					itmInfo.put("id", projectTypeId);
					itmInfo.put("name", projectTypeComInfo.getProjectTypename(projectTypeId));
					browserValueObjs.add(itmInfo);
				}
				break;
			case 245: // 工作类型
				WorkTypeComInfo workTypeComInfo = new WorkTypeComInfo();
				for (String workTypeId : browserValueIds) {
					Map<String, Object> itmInfo = new HashMap<String, Object>();
					itmInfo.put("id", workTypeId);
					itmInfo.put("name", workTypeComInfo.getWorkTypename(workTypeId));
					browserValueObjs.add(itmInfo);
				}
				break;
			case 258: // 国家
				CountryComInfo countryComInfo = new CountryComInfo();
				for (String countryId : browserValueIds) {
					Map<String, Object> countryInfo = new HashMap<String, Object>();
					countryInfo.put("id", countryId);
					countryInfo.put("name", countryComInfo.getCountryname(countryId));
					browserValueObjs.add(countryInfo);
				}
				break;
			case 264: // 客户状态
				CustomerStatusComInfo cusStatusComInfo = new CustomerStatusComInfo();
				for (String cusStatusId : browserValueIds) {
					Map<String, Object> cusStatusInfo = new HashMap<String, Object>();
					cusStatusInfo.put("id", cusStatusId);
					cusStatusInfo.put("name", cusStatusComInfo.getCustomerStatusname(cusStatusId));
					browserValueObjs.add(cusStatusInfo);
				}
				break;
			case 267: // 角色
				RolesComInfo roleComInfo = new RolesComInfo();
				for (String roleId : browserValueIds) {
					Map<String, Object> roleInfo = new HashMap<String, Object>();
					roleInfo.put("id", roleId);
					roleInfo.put("name", roleComInfo.getRolesRemark(roleId));
					browserValueObjs.add(roleInfo);
				}
				break;
			case 161:// 自定义按钮
			case 162:
				if(browserBean!=null){
					Map<String, Object> map = browserBean.getCompleteParams();
					if(map!=null&&map.containsKey("fielddbtype")){
						dbtype = StringHelper.null2String(map.get("fielddbtype"));
						Browser browser=(Browser) StaticObj.getServiceByFullname(dbtype, Browser.class);
						for(int j=0;j<browserValueIds.length;j++){
							String curid=browserValueIds[j];
							BrowserBean bb=browser.searchById(curid);
							String name=Util.null2String(bb.getName());
							name = name.replaceAll("<", "&lt;");
							name = name.replaceAll(">", "&gt;");

							Map<String, Object> item = new HashMap<String, Object>();
							item.put("id", curid);
							item.put("name", name);
							browserValueObjs.add(item);
						}
					}
				}
				break;
			case 256:// 自定义树形按钮
			case 257:
				CustomTreeUtil customTreeUtil = new CustomTreeUtil();
				if(browserBean!=null){
					Map<String, Object> map = browserBean.getCompleteParams();
					if(map!=null&&map.containsKey("fielddbtype")){
						dbtype = StringHelper.null2String(map.get("fielddbtype"));
						String values = StringUtils.join(browserValueIds);
						String name = customTreeUtil.getTreeFieldShowName(values,dbtype,"onlyname");
						String[] names = name.split(",");
						if(browserValueIds.length==names.length){
							for (int i = 0; i < names.length; i++) {
								Map<String, Object> item = new HashMap<String, Object>();
								item.put("id", browserValueIds[i]);
								item.put("name", names[i]);
								browserValueObjs.add(item);
							}
						}

					}
				}
				break;
			default:
				BrowserComInfo BrowserComInfo = new BrowserComInfo();
				String tablename1=BrowserComInfo.getBrowsertablename(type+""); //浏览框对应的表,比如人力资源表
				String columname=BrowserComInfo.getBrowsercolumname(type+""); //浏览框对应的表名称字段
				String keycolumname=BrowserComInfo.getBrowserkeycolumname(type+"");   //浏览框对应的表值字段
				String fieldvalue = StringUtils.join(browserValueIds);
				fieldvalue=deleteFirstAndEndchar(fieldvalue,",");
				String sql = "";
				if(fieldvalue.indexOf(",")!=-1){
					sql= "select "+keycolumname+","+columname+" from "+tablename1+" where "+keycolumname+" in( "+fieldvalue+")";
				}
				else {
					sql= "select "+keycolumname+","+columname+" from "+tablename1+" where "+keycolumname+"="+fieldvalue;
				}

				RecordSet.execute(sql);
				while(RecordSet.next()){
					Map<String, Object> item = new HashMap<String, Object>();
					item.put("id", RecordSet.getString(1));
					item.put("name", Util.toScreen(RecordSet.getString(2),user.getLanguage()));
					browserValueObjs.add(item);
				}
				break;
		}
		com.api.browser.bean.BrowserBean browserProp = conditionItem.getBrowserConditionParam();
		browserProp.setReplaceDatas(browserValueObjs);
		return conditionItem;
	}

	/**
	 * 将前台传入的表单字段键值对中的 key 转成 $key$,符合sql中的格式用来做替换
	 *
	 * @param map
	 * @return
	 */
	public Map dealFormParams(Map<String, Object> map, String currenttime) {
		Map<String, String> dealFormMap = new HashMap<String, String>();
		if (null != map && map.size() > 0) {
			Set keyset = map.keySet();
			for (Iterator it = keyset.iterator(); it.hasNext(); ) {
				String keyname = (String) it.next();
				int index = keyname.indexOf("_"+currenttime);
				if(index!=-1){
					String reallyKey = keyname.substring(0,index);
					String keyvalue = Util.null2String(map.get(keyname));
					keyvalue = returnSpecialChar(keyvalue);
					//if ("".equals(keyvalue)) {
					//keyvalue = "''";
					//}
					dealFormMap.put("$" + reallyKey + "$", keyvalue);
				}
			}
		}
		return dealFormMap;
	}

	/**
	 * 查询列表高级查询： 将前台传入的表单字段键值对中的 key 转成 $key$,符合sql中的格式用来做替换
	 *@param flag 判断是查询条件上的表单字段，还是查询语句中的，true是查询语句的
	 * @param map
	 * @return
	 */
	public Map dealFormParams2(Map<String, Object> map, String currenttime,boolean flag) {
		Map<String, String> dealFormMap = new HashMap<String, String>();
		if (null != map && map.size() > 0) {
			StringBuffer fields = new StringBuffer();
			Set keyset = map.keySet();
			for (Iterator it = keyset.iterator(); it.hasNext(); ) {
				String keyname = (String) it.next();
				String[] keynames = keyname.split("_");

				if (keynames.length >1  && keyname.startsWith("con_")) {
					int index = keyname.lastIndexOf("_");
					String fieldid = keynames[keynames.length-1];//这个是字段id
					fields.append(fieldid);
					fields.append(",");
				}
			}

			//设置替换的字段
			if(fields.length()>0){
				String sql = "select t.id,t.fieldname,t.detailtable from workflow_billfield t where t.id in("+fields.deleteCharAt(fields.length() - 1)+")";
				RecordSet rs = new RecordSet();
				rs.executeQuery(sql);
				while(rs.next()){
					String reallyKey = rs.getString("fieldname");
					String detailtable = rs.getString("detailtable");
					String keyvalue = Util.null2String(map.get("con_"+rs.getString("id")));
					keyvalue = returnSpecialChar(keyvalue);
					if(null == detailtable || detailtable.equals("")){
						dealFormMap.put("$" + reallyKey + "$", keyvalue);
					}else{
						dealFormMap.put("$" + detailtable+"_"+reallyKey + "$", keyvalue);
					}

				}
			}
		}
		return dealFormMap;
	}
	/**
	 * 查询列表高级查询： 将前台传入的表单字段键值对中的 key 转成 $key$,符合sql中的格式用来做替换,存字段类型
	 *@param flag 判断是查询条件上的表单字段，还是查询语句中的，true是查询语句的
	 * @param map
	 * @return
	 */
	public Map dealFormParams3(Map<String, Object> map, String currenttime,boolean flag) {
		Map<String, String> dealFormMap = new HashMap<String, String>();
		if (null != map && map.size() > 0) {
			StringBuffer fields = new StringBuffer();
			Set keyset = map.keySet();
			for (Iterator it = keyset.iterator(); it.hasNext(); ) {
				String keyname = (String) it.next();
				String[] keynames = keyname.split("_");

				if (keynames.length >1  && keyname.startsWith("con_")) {
					int index = keyname.lastIndexOf("_");
					String fieldid = keynames[keynames.length-1];//这个是字段id
					fields.append(fieldid);
					fields.append(",");
				}
			}

			//设置替换的字段
			if(fields.length()>0){
				String sql = "select t.id,t.fieldname,t.detailtable,t.fieldhtmltype from workflow_billfield t where t.id in("+fields.deleteCharAt(fields.length() - 1)+")";
				RecordSet rs = new RecordSet();
				rs.executeQuery(sql);
				while(rs.next()){
					String reallyKey = rs.getString("fieldname");
					String detailtable = rs.getString("detailtable");
					String fieldhtmltype = Util.null2String(rs.getString("fieldhtmltype"));
					if(null == detailtable || detailtable.equals("")){
						dealFormMap.put("$" + reallyKey + "$", fieldhtmltype);
					}else{
						dealFormMap.put("$" + detailtable+"_"+reallyKey + "$", fieldhtmltype);
					}

				}
			}
		}
		return dealFormMap;
	}

	/**
	 * 对请求参数 和 后台获取的Map做匹配，将符合的键值对放入searchvaluemap中
	 *
	 * @param searchfieldMap 后台初始化browser得到的map（主要是数据展现集成中配置的查询参数）
	 * @param params         request中的请求参数
	 * @param searchvaluemap
	 */
	private void initSearchValueMap(Map searchfieldMap, Map<String, Object> params, Map searchvaluemap) {
		if (null != searchfieldMap) {
			Set keyset = searchfieldMap.keySet();
			for (Iterator it = keyset.iterator(); it.hasNext(); ) {
				String keyname = (String) it.next();
				String keyvalue = Util.null2String(params.get(keyname));
				keyvalue = returnSpecialChar(keyvalue);
				if (!"".equals(keyvalue))
					searchvaluemap.put(keyname, keyvalue);
			}
		}
	}


	/**
	 * 返回包含特殊字符的字符串
	 *
	 * @param paramvalue
	 * @return
	 */
	private static String returnSpecialChar(String paramvalue) {
		paramvalue = paramvalue.replaceAll("@#add#@", "+");
		return paramvalue;
	}

	/**
	 * 用正则表达式将sql里所有表单变量转换成小写，保证正常替换
	 *
	 * @param sql
	 * @return
	 */

	private String replaceFieldValue(String sql) {
		Pattern p = Pattern.compile("(\\$[a-zA-Z][a-zA-Z0-9_]*\\$)");
		Matcher m = p.matcher(sql);
		while (m.find()) {
			String fieldname = m.group();
			String fieldnamebak="";
			if(fieldname.contains(".")){
				fieldnamebak = fieldname.substring(0,fieldname.lastIndexOf(".")) + "_" +fieldname.substring(fieldname.lastIndexOf(".") + 1);
			}
			sql = sql.replace(fieldname, fieldnamebak == ""? fieldname.toLowerCase()  : fieldnamebak.toLowerCase());//替换字段值
		}
		return sql;
	}

	/**
	 * 对多值进行处理，加上单引号
	 *
	 * @param fieldvalue
	 * @return
	 */
	public String rebuildMultiFieldValue(String fieldvalue) {
		String result = "";
		if (fieldvalue.indexOf(",") > -1) {
			String[] array = fieldvalue.split(",");
			for (int i = 0; i < array.length; i++) {
				if (!array[i].equals("")) {
					if (result.equals("")) {
						result += "'";
					} else {
						result += ",'";
					}

					result += array[i] + "'";
				}
			}
		} else {
			result = fieldvalue;
		}

		return result;
	}


	/**
	 * 根据日期条件类型获取日期范围
	 * @param tmpvalue_select
	 * @param tmpvalue_start
	 * @param tmpvalue_end
	 * @return
	 */
	public static Map<String,String> getDateRangeByDateField(String tmpvalue_select,String tmpvalue_start,String tmpvalue_end){
		Calendar calendar = Calendar.getInstance();
		Date date = calendar.getTime();
		Map<String,String> map  = new HashMap<String,String>();
		String start = "";
		String end = "";
		Date date1 = new Date();   //单独处理本周
		if("1".equals(tmpvalue_select)){//今天
			start = DateHelper.getCurrentDate();
			end = DateHelper.getCurrentDate();
		}else if("2".equals(tmpvalue_select)){//本周
			//calendar.set(Calendar.DAY_OF_WEEK, calendar.getActualMinimum(Calendar.DAY_OF_WEEK));//周日
			//date = calendar.getTime();
			start = DateHelper.getFirstDayOfWeek(date1);

			//calendar.set(Calendar.DAY_OF_WEEK, calendar.getActualMaximum(Calendar.DAY_OF_WEEK));//周六
			//date = calendar.getTime();
			end = DateHelper.getLastDayOfWeek(date1);
		}else if("3".equals(tmpvalue_select)){//本月
			start = DateHelper.getFirstDayOfMonthWeek(date);
			end = DateHelper.getLastDayOfMonthWeek(date);
		}else if("4".equals(tmpvalue_select)){//本季
			start = getQuarterStart();
			end = getQuarterEnd();
		}else if("5".equals(tmpvalue_select)){//本年
			int year = Util.getIntValue(DateHelper.getCurrentYear());
			start = getFirstDayOfYear(year);
			end = getLastDayOfYear(year);
		}else if("6".equals(tmpvalue_select)){//指定日期范围
			start = tmpvalue_start;
			end = tmpvalue_end;
		}else if("7".equals(tmpvalue_select)){//上个月
			calendar.add(Calendar.MONTH, -1);
			date = calendar.getTime();
			start = DateHelper.getFirstDayOfMonthWeek(date);
			end = DateHelper.getLastDayOfMonthWeek(date);
		}else if("8".equals(tmpvalue_select)){//上一年
			int year = Util.getIntValue(DateHelper.getCurrentYear())-1;
			start = getFirstDayOfYear(year);
			end = getLastDayOfYear(year);
		}else if("9".equals(tmpvalue_select)){//昨天
			start = DateHelper.getYesterday();
			end = DateHelper.getYesterday();
		}else if("10".equals(tmpvalue_select)){//明天
			start = DateHelper.getTomorrow();
			end = DateHelper.getTomorrow();
		}else if("11".equals(tmpvalue_select)){//上周（周一~周日）
			start =DateHelper.getLastWeek().split(",")[0];
			end = DateHelper.getLastWeek().split(",")[1];
		}else if("12".equals(tmpvalue_select)){//下周（周一~周日）
			start = DateHelper.getNextWeek().split(",")[0];
			end = DateHelper.getNextWeek().split(",")[1];
		}
		map.put("startdate", start);
		map.put("enddate", end);
		return map;
	}

	/**
	 * 获取某年第一天日期 
	 * @param year 年份 
	 * @return Date
	 */
	public static String getFirstDayOfYear(int year){
		Calendar calendar = Calendar.getInstance();
		calendar.clear();
		calendar.set(Calendar.YEAR, year);
		Date currYearFirst = calendar.getTime();
		String d = DateHelper.convertDateIntoYYYYMMDDStr(currYearFirst);
		return d;
	}

	/**
	 * 获取某年最后一天日期 
	 * @param year 年份 
	 * @return Date
	 */
	public static String getLastDayOfYear(int year){
		Calendar calendar = Calendar.getInstance();
		calendar.clear();
		calendar.set(Calendar.YEAR, year);
		calendar.roll(Calendar.DAY_OF_YEAR, -1);
		Date currYearLast = calendar.getTime();
		String d = DateHelper.convertDateIntoYYYYMMDDStr(currYearLast);
		return d;
	}

	/**
	 * 当前季度的开始日期
	 * @return
	 */
	public static String getQuarterStart() {
		Calendar c = Calendar.getInstance();
		int currentMonth = c.get(Calendar.MONTH) + 1;
		if (currentMonth >= 1 && currentMonth <= 3)
			c.set(Calendar.MONTH, 0);
		else if (currentMonth >= 4 && currentMonth <= 6)
			c.set(Calendar.MONTH, 3);
		else if (currentMonth >= 7 && currentMonth <= 9)
			c.set(Calendar.MONTH, 6);
		else if (currentMonth >= 10 && currentMonth <= 12)
			c.set(Calendar.MONTH, 9);
		c.set(Calendar.DATE, 1);
		Date date = c.getTime();
		String d = DateHelper.convertDateIntoYYYYMMDDStr(date);
		return d;
	}

	/**
	 * 当前季度的结束日期
	 * @return
	 */
	public static String getQuarterEnd() {
		Calendar c = Calendar.getInstance();
		int currentMonth = c.get(Calendar.MONTH) + 1;
		if (currentMonth >= 1 && currentMonth <= 3) {
			c.set(Calendar.MONTH, 2);
			c.set(Calendar.DATE, 31);
		} else if (currentMonth >= 4 && currentMonth <= 6) {
			c.set(Calendar.MONTH, 5);
			c.set(Calendar.DATE, 30);
		} else if (currentMonth >= 7 && currentMonth <= 9) {
			c.set(Calendar.MONTH, 8);
			c.set(Calendar.DATE, 30);
		} else if (currentMonth >= 10 && currentMonth <= 12) {
			c.set(Calendar.MONTH, 11);
			c.set(Calendar.DATE, 31);
		}
		Date date = c.getTime();
		String d = DateHelper.convertDateIntoYYYYMMDDStr(date);
		return d;
	}



	/**
	 * 处理查询语句，将查询条件转换(针对选择框处理)
	 *
	 * @param search       sql
	 * @param searchByName sql
	 * @param allFieldMap  表单集合
	 * @param flag         是否需要处理多个值的情况 true多值
	 * @return
	 */
	private Map<String, String> dealSearch_(String search, String searchByName, Map<String, String> allFieldTypeMap,Map<String, String> allFieldMap, boolean flag,String wf_billid,String formid) {
		Map<String, String> map = new HashMap<String, String>();
		RecordSet rs = new RecordSet();
		if (allFieldMap != null && allFieldMap.size() > 0) {
			ResourceComInfo resourceComInfo= null;
			DepartmentComInfo departmentComInfo = null;
			SubCompanyComInfo subCompanyComInfo  =null;
			try {
				resourceComInfo = new ResourceComInfo();
				departmentComInfo = new DepartmentComInfo();
				subCompanyComInfo = new SubCompanyComInfo();
			} catch (Exception e) {
				e.printStackTrace();
			}
			Set keyset = allFieldMap.keySet();
			for (Iterator it = keyset.iterator(); it.hasNext(); ) {
				String keyname = (String) it.next();
				String keyvalue = Util.null2String(allFieldMap.get(keyname));
				if ("''".equals(keyvalue) || "".equals(keyvalue)) {
					String  fieldhtmltype ="";
					boolean isDetailTable = false;
					String keyname_ =keyname.replaceAll("\\$", "");
					Pattern pat2 = Pattern.compile("_dt\\d+");
					Matcher m2=pat2.matcher(keyname_);
					m2=pat2.matcher(keyname_);
					while(m2.find()){
						isDetailTable=true;
					}
					fieldhtmltype = Util.null2String(allFieldTypeMap.get(keyname));
					if(fieldhtmltype.equals("")){
						String billid ="";
						String sql = "select fieldhtmltype from  workflow_billfield   where fieldname =?  and billid =?";
						if("".equals(wf_billid)){//建模字段$uf_xxx_dtx_建模字段$,$建模字段$
							billid = formid;
						}else{
							billid = wf_billid;
						}

						if(!isDetailTable){
							rs.executeQuery(sql, keyname_,billid);
						}else{
							rs.executeQuery(sql, keyname_.replaceAll("^.*_dt\\d+_", ""),billid);
						}

						if(rs.next()){
							fieldhtmltype=rs.getString(1);
						}
					}
					if(fieldhtmltype.equals("5")){
						keyvalue = "9999";
					}
				}
				if (flag) keyvalue = rebuildMultiFieldValue(keyvalue);//处理多值
				try {
					if(keyvalue.indexOf("[object Object]")>-1){//是人员这个浏览框从快捷搜索传递过来的
						String[] values = Util.splitString(keyvalue,",");
						if(values.length<1){
							keyvalue="";
						}
						if("-1".equals(values[0])) {
							keyvalue ="( select id from hrmresource where departmentid ="+resourceComInfo.getDepartmentID(user.getUID() + "")+")";
						}else if("-2".equals(values[0])) {
							String departid = resourceComInfo.getDepartmentID(user.getUID()+"");
							keyvalue ="( select id from hrmresource where departmentid in("+departmentComInfo.getAllChildDepartId(departid,departid)+"))";
						}else if("-3".equals(values[0])) {
							String subcomid = resourceComInfo.getSubCompanyID(user.getUID()+"");
							keyvalue="( select id from hrmresource where subcompanyid1 ="+subcomid+")";
						}else if("-4".equals(values[0])) {
							String subcomid = resourceComInfo.getSubCompanyID(user.getUID()+"");
							keyvalue="( select id from hrmresource where subcompanyid1 in (select id from hrmsubcompany where supsubcomid="+subcomid+" or id= "+subcomid+" ))";
						}else if("-5".equals(values[0])) {
							keyvalue =  Util.null2String(values[1]);
						}else if("-6".equals(values[0])) {
							keyvalue = user.getUID()+"";
						}else if("-7".equals(values[0])) {
							keyvalue = user.getManagerid();
						}else if("-8".equals(values[0])) {
							rs.executeQuery("select * from hrmresource where managerid = ? ",user.getUID());
							if(rs.next()){
								keyvalue = "(select id  from hrmresource where managerid = "+user.getUID()+" )";
							}else{
								keyvalue="0";
							}
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				search = search.replace(keyname.toLowerCase(), keyvalue);
				searchByName.replace(keyname.toLowerCase(), keyvalue);
			}
		}
		map.put("search", search);
		map.put("searchByName", searchByName);
		return map;
	}

	/**
	 * 处理查询语句，将查询条件转换
	 *
	 * @param search       sql
	 * @param searchByName sql
	 * @param allFieldMap  表单集合
	 * @param flag         是否需要处理多个值的情况 true多值
	 * @return
	 */
	private Map<String, String> dealSearch(String search, String searchByName, Map<String, String> allFieldMap, boolean flag) {
		Map<String, String> map = new HashMap<String, String>();
		if (allFieldMap != null && allFieldMap.size() > 0) {
			Set keyset = allFieldMap.keySet();
			for (Iterator it = keyset.iterator(); it.hasNext(); ) {
				String keyname = (String) it.next();
				String keyvalue = Util.null2String(allFieldMap.get(keyname));
				if (flag) keyvalue = rebuildMultiFieldValue(keyvalue);//处理多值
				search = search.replace(keyname.toLowerCase(), keyvalue);
				searchByName.replace(keyname.toLowerCase(), keyvalue);
			}
		}
		map.put("search", search);
		map.put("searchByName", searchByName);
		return map;
	}

	/**
	 *  拼接高级搜索条件
	 * @return
	 */
	public String getSearchSqlWhere(Map<String, Object> params, RecordSet recordSet, String maintableAlias, String detailtableAlias, String vdatasourceDBtype, String sqlwhere_con, boolean isoracle, boolean isdb2,boolean isSearchByAdv) {
		while (recordSet.next()){
			String q = Util.null2String(params.get("q")); //TODO xzl 快捷搜索字段
			String name = recordSet.getString("name");
			String htmltype = recordSet.getString("httype");
			String type = recordSet.getString("type");
			String id = recordSet.getString("id");
			String dbtype = Util.null2String(recordSet.getString("dbtype"));
			String field_viewtype = Util.null2String(recordSet.getString("viewtype"));
			String isQuery = Util.null2String(recordSet.getString("isquery"));
			String isQuickSearch = Util.null2String(recordSet.getString("isquicksearch"));
			String namestr = "con"+id+"_value";
			// 如果是高级搜索，但是不是查询条件
			if(isSearchByAdv &&  !"1".equals(isQuery)) continue;

			if(!isSearchByAdv){
				namestr = "cus"+id+"_value";

			}
			String multiselectValue = ""+Util.null2String(params.get("multiselectValue_"+namestr));
			String tmpvalue = Util.null2String(params.get(namestr));
			String tmpvalue1 = ""+Util.null2String(recordSet.getString(namestr+"1"));
			String tmpvalue_select = Util.null2String(params.get(namestr+"_select"));
			String tmpvalue_start = Util.null2String(params.get(namestr+"_start"));
			String tmpvalue_end = Util.null2String(params.get(namestr+"_end"));

			//控制时间
			if("".equals(tmpvalue_end)){
				String[] time = Util.null2String(params.get(namestr+"_start")).split(",");
				if(time.length == 2){
					tmpvalue_start = (time[0].compareTo(time[1])) > 0 ? time[1] : time[0];
					tmpvalue_end = (time[0].compareTo(time[1])) > 0 ? time[0] : time[1];
				}else if(time.length == 1){
					tmpvalue_start = time[0];
				}
			}

			/*
			 * 初始化创建日期   -1
			 * 创建人           -2
			 */
			if(id.equals("-1")){
				name="modedatacreatedate";
				htmltype="3";
				type="2";
			}else if(id.equals("-2")){
				name="modedatacreater";
				htmltype="3";
				type="1";
			}else if(id.equals("-3")){
				name="id";
				htmltype="1";
				type="1";
			}else if(id.equals("-5")){
				name="modedatastatus";
				htmltype="5";
				type="1";
			}else if(id.equals("-7")){
				name="modedatamodifier";
				htmltype="3";
				type="1";
			}else if(id.equals("-8")){
				name="modedatamodifydatetime";
				htmltype="3";
				type="290";
			}else if(id.equals("-9")){
				name="seclevel";
				htmltype="5";
				type="1";
			}
			// CHANGE START
			else if (id.equals("-10")) {
				// 业务ID
				id = "-10";
				name = ShardingHelper.KEY_FORM_BIZ_ID;
				htmltype = "1";
				type = "1";
			}
			// CHANGE END
			String tableAlias = "";
			tableAlias = maintableAlias+".";
			if("1".equals(field_viewtype)){
				tableAlias = detailtableAlias+".";
			}

			if (!q.isEmpty() && "1".equals(isQuickSearch)){
				if(!sqlwhere_con.equals("")){
					sqlwhere_con += " or ";
				}
				if(vdatasourceDBtype.contains("oracle")){
					sqlwhere_con += "LOWER(to_char(" + tableAlias + name + ")) like '%"+Util.StringReplace(q,"%","/%")+"%' ESCAPE '/' ";
				}else if(vdatasourceDBtype.contains("mysql")){
					sqlwhere_con +="LOWER(convert(" + tableAlias + name + ",char)) like '%"+Util.StringReplace(q,"%","/%")+"%' ESCAPE '/' ";
				}
				else if(vdatasourceDBtype.contains("postgresql")){
					sqlwhere_con += "LOWER(to_char(" + tableAlias + name + ")) like '%"+Util.StringReplace(q,"%","/%")+"%' ESCAPE '/' ";
				}
				else{
					sqlwhere_con +="LOWER(convert(varchar(4000)," + tableAlias + name + ")) like '%"+Util.StringReplace(q,"%","/%")+"%' ESCAPE '/' ";
				}
				continue;
			}

			if("".equals(tmpvalue)&&"".equals(tmpvalue1)&&"".equals(multiselectValue)
					&&("".equals(tmpvalue_select)||"0".equals(tmpvalue_select))&&"".equals(tmpvalue_start)&&"".equals(tmpvalue_end)){
				continue;
			}

			tmpvalue = tmpvalue.replace("'", "''");
			tmpvalue1 = tmpvalue1.replace("'", "''");
			tmpvalue=Util.StringReplace(tmpvalue,"/","//");
			tmpvalue1=Util.StringReplace(tmpvalue1,"/","//");
			tmpvalue=Util.StringReplace(tmpvalue,"%","/%");
			tmpvalue1=Util.StringReplace(tmpvalue1,"%","/%");
			String tmpcolname = name;
			String tmpopt = "";
			if(htmltype.equals("1")&& type.equals("1")){  //文本框 单行文本不区分大小写
				String searchsettings = "1";
				RecordSet rs = new RecordSet();
				rs.executeQuery("select * from formEngineSet t where t.isdelete=0");
				if(rs.next()){
					searchsettings = Util.null2String(rs.getString("searchsettings"));
				}
				ArrayList tempvalues=Util.TokenizerString(Util.StringReplace(tmpvalue,"　"," ")," ");
				if(!"1".equals(searchsettings)){
					tempvalues.clear();     //开启不空格查询，先清除数组，再添加该值为唯一值。
					tempvalues.add(tmpvalue);
				}
				sqlwhere_con += " and (";
				boolean isPostgresql = vdatasourceDBtype.contains("postgresql");//"postgresql".equalsIgnoreCase(recordSet.getDBType());
				for(int k=0;k<tempvalues.size();k++){
					if (isPostgresql) {
						if(k==0) sqlwhere_con += " LOWER(to_char("+tableAlias+tmpcolname+")) ";
						else  sqlwhere_con += " or LOWER(to_char("+tableAlias+tmpcolname+")) ";
					} else {
						if(k==0) sqlwhere_con += " LOWER("+tableAlias+tmpcolname+") ";
						else  sqlwhere_con += " or LOWER("+tableAlias+tmpcolname+") ";
					}
					tmpvalue=Util.StringReplace(Util.StringReplace((String)tempvalues.get(k),"+","%"),"＋","%");
					tmpvalue=tmpvalue.toLowerCase();
					if(!isoracle&&!isdb2){
						int indx=tmpvalue.indexOf("[");
						if(indx<0) indx=tmpvalue.indexOf("]");
						if(indx<0){
							sqlwhere_con += " like '%"+tmpvalue+"%' ESCAPE '/' ";
						}else{
							sqlwhere_con += " like '%"+Util.StringReplace(Util.StringReplace(Util.StringReplace(tmpvalue,"/","//"),"[","/["),"]","/]")+"%' ESCAPE '/' ";
						}
					}else{
						sqlwhere_con += " like '%"+tmpvalue+"%' ESCAPE '/' ";
					}
				}
			} else if(htmltype.equals("2")){//多行文本
				ArrayList tempvalues=Util.TokenizerString(Util.StringReplace(tmpvalue,"　"," ")," ");
				sqlwhere_con += " and (";
				for(int k=0;k<tempvalues.size();k++){
					String temp = tableAlias+tmpcolname;
					if ("sqlserver".equals(vdatasourceDBtype)) {
						temp="convert(varchar(max),"+temp+")";
					}
					if(k==0) sqlwhere_con += " lower("+temp+") ";
					else  sqlwhere_con += " or lower("+temp+") ";
					tmpvalue=Util.StringReplace(Util.StringReplace((String)tempvalues.get(k),"+","%"),"＋","%");
					tmpvalue=tmpvalue.toLowerCase();
					if(!isoracle&&!isdb2){
						int indx=tmpvalue.indexOf("[");
						if(indx<0) indx=tmpvalue.indexOf("]");
						if(indx<0){
							sqlwhere_con += " like '%"+Util.StringReplace(tmpvalue,"%","/%")+"%' ESCAPE '/' ";
						}else{
							sqlwhere_con += " like '%"+Util.StringReplace(Util.StringReplace(Util.StringReplace(Util.StringReplace(tmpvalue,"/","//"),"[","/["),"]","/]"),"%","/%")+"%' ESCAPE '/' ";
						}
					}else{
						sqlwhere_con += " like '%"+Util.StringReplace(tmpvalue,"%","/%")+"%' ESCAPE '/' ";
					}
				}
			} else if(htmltype.equals("1")&& !type.equals("1")){  //数字   <!--大于或等于 ,小于或等于 -->
				tmpvalue = tmpvalue_start;
				tmpvalue1 = tmpvalue_end;
				if(!tmpvalue.equals("")){
					if(type.equals("5")){//金额转换
						if(vdatasourceDBtype.equals("oracle")){
							sqlwhere_con += " and "+tableAlias+tmpcolname+  " is not null and (cast((CASE WHEN ("+tableAlias+tmpcolname+"||'') is null THEN '0' WHEN ("+tableAlias+tmpcolname+"||'') =' ' THEN '0' ELSE Replace(("+tableAlias+tmpcolname+"||''), ',', '') END) as number(30,6))";
						}else if(vdatasourceDBtype.equals("mysql")){
							sqlwhere_con += "and "+tableAlias+tmpcolname+  " is not null and (cast((CASE ("+tableAlias+tmpcolname+" REGEXP '-[^0-9.]') WHEN 1 THEN '0' WHEN 0 THEN replace("+tableAlias+tmpcolname+",',','') ELSE '0' END) as decimal(30,6))";
						}
						else if(vdatasourceDBtype.equals("postgresql")){
							sqlwhere_con += " and "+tableAlias+tmpcolname+  " is not null and (cast((CASE WHEN ("+tableAlias+tmpcolname+"||'') is null THEN '0' WHEN ("+tableAlias+tmpcolname+"||'') =' ' THEN '0' ELSE Replace(("+tableAlias+tmpcolname+"||''), ',', '') END) as number(30,6))";
						}
						else{//金额千分位是varchar类型
							sqlwhere_con += " and "+tableAlias+tmpcolname+ " is not null and (cast((CASE isnumeric ("+tableAlias+tmpcolname+") WHEN 0 THEN '0' WHEN 1 THEN replace("+tableAlias+tmpcolname+",',','') ELSE '0' END) as decimal(30,6))";
						}
					}else{
						sqlwhere_con += "and ("+tableAlias+tmpcolname;
					}
					sqlwhere_con+=" >="+tmpvalue +" ";
				}
				if(!tmpvalue1.equals("")){
					if(type.equals("5")){//金额转换
						if(vdatasourceDBtype.equals("oracle")){
							sqlwhere_con += " and "+tableAlias+tmpcolname+  " is not null and cast((CASE WHEN ("+tableAlias+tmpcolname+"||'') is null THEN '0' WHEN ("+tableAlias+tmpcolname+"||'') =' ' THEN '0' ELSE Replace(("+tableAlias+tmpcolname+"||''), ',', '') END) as number(30,6))";
						}else if(vdatasourceDBtype.equals("mysql")){
							sqlwhere_con += " and " +tableAlias+tmpcolname+  " is not null  and cast((CASE ("+tableAlias+tmpcolname+" REGEXP '-[^0-9.]') WHEN 1 THEN '0' WHEN 0 THEN replace("+tableAlias+tmpcolname+",',','') ELSE '0' END) as decimal(30,6))";
						}
						else if(vdatasourceDBtype.equals("postgresql")){
							sqlwhere_con += " and "+tableAlias+tmpcolname+  " is not null and cast((CASE WHEN ("+tableAlias+tmpcolname+"||'') is null THEN '0' WHEN ("+tableAlias+tmpcolname+"||'') =' ' THEN '0' ELSE Replace(("+tableAlias+tmpcolname+"||''), ',', '') END) as number(30,6))";
						}
						else{//金额千分位是varchar类型
							sqlwhere_con += " and " +tableAlias+tmpcolname+  " is not null and cast((CASE isnumeric ("+tableAlias+tmpcolname+") WHEN 0 THEN '0' WHEN 1 THEN replace("+tableAlias+tmpcolname+",',','') ELSE '0' END) as decimal(30,6))";
						}
					}else{
						sqlwhere_con += " and "+tableAlias+tmpcolname;
					}
					sqlwhere_con+=" <="+tmpvalue1 +" ";
				}
			} else if(htmltype.equals("4")){   //check类型 = !=
                /*sqlwhere_con += "and ("+tableAlias+tmpcolname;
                if(!tmpvalue.equals("1")){
                    sqlwhere_con+="<>'1' ";
                }else{
                    sqlwhere_con +="='1' ";
                }*/

				if ("1".equals(tmpvalue)) {
					sqlwhere_con += "and ("+tableAlias+tmpcolname;
					sqlwhere_con+=" = '1' ";
				} else if ("2".equals(tmpvalue)) {
					sqlwhere_con += "and ("+tableAlias+tmpcolname;
					sqlwhere_con+= "= '0' or "+tableAlias+tmpcolname+" is null  ";
				}
			} else if(htmltype.equals("5")){  //选择框   = != like
				if(!"".equals(multiselectValue)){
					sqlwhere_con += "and ( ";
					String multiselectSqlwhere_con="";

					if(vdatasourceDBtype.equals("oracle")){
						tmpcolname = " ','||to_char("+tableAlias+tmpcolname+")||',' ";
					}else if("mysql".equalsIgnoreCase(vdatasourceDBtype)) {
						tmpcolname = " concat(',',convert("+tableAlias+tmpcolname+",char),',') ";
					}
					else if(vdatasourceDBtype.equals("postgresql")){
						tmpcolname = " ','||to_char("+tableAlias+tmpcolname+")||',' ";
					}
					else {
						tmpcolname = " ','+convert(varchar(max),"+tableAlias+tmpcolname+")+',' ";
					}

					String[] multiselectValue_tmpvalueArray  = multiselectValue.split(",");
					for(int n=0;n<multiselectValue_tmpvalueArray.length;n++){
						if("".equals(multiselectValue_tmpvalueArray[n])){
							continue;
						}

						multiselectSqlwhere_con+= tmpcolname;
						if(tmpopt.equals("1")||"".equals(tmpopt))
							//multiselectSqlwhere_con+=" ="+multiselectValue_tmpvalueArray[n] +" or ";
							multiselectSqlwhere_con += " like '%," + multiselectValue_tmpvalueArray[n] + ",%'  or ";
						if(tmpopt.equals("2"))
							multiselectSqlwhere_con+=" <>"+multiselectValue_tmpvalueArray[n] +" or ";
					}
					if(multiselectSqlwhere_con.length()>0){
						multiselectSqlwhere_con = multiselectSqlwhere_con.substring(0,multiselectSqlwhere_con.length()-3);
					}
					sqlwhere_con+=multiselectSqlwhere_con;
				}else{
					sqlwhere_con += "and ("+tableAlias+tmpcolname;
					sqlwhere_con+=" ="+tmpvalue +" ";
				}
			} else if(htmltype.equals("3") && (type.equals("1")||type.equals("9")||type.equals("4")||type.equals("7")||type.equals("8")||type.equals("16"))){//浏览框单人力资源  条件为多人力 (int  not  in),条件为多文挡,条件为多部门,条件为多客户,条件为多项目,条件为多请求
				if(!tmpvalue.equals("")){
					sqlwhere_con += "and ("+tableAlias+tmpcolname;
					sqlwhere_con+=" in ("+tmpvalue +") ";
				} else if(null != multiselectValue && !multiselectValue.equals("")){
					sqlwhere_con += "and ("+tableAlias+tmpcolname;
					sqlwhere_con+=" in ("+multiselectValue +") ";
				}
			}else if(htmltype.equals("3") && type.equals("24")){//职位的安全级别 > >= = < !  and > >= = < !
				if(!tmpvalue.equals("") && !tmpvalue1.equals("") ){
					if(!tmpvalue.equals("")){
						sqlwhere_con += "and ("+tableAlias+tmpcolname;
						sqlwhere_con+=" >="+tmpvalue +" ";
					}
					if(!tmpvalue1.equals("")){
						sqlwhere_con += " and "+tableAlias+tmpcolname;
						sqlwhere_con+=" <="+tmpvalue1 +" ";
					}
				}else if(!tmpvalue.equals("")){
					sqlwhere_con += "and ("+tableAlias+tmpcolname;
					sqlwhere_con+=" ="+tmpvalue +" ";
				}
				if(null != multiselectValue && !multiselectValue.equals("")){
					sqlwhere_con += "and ("+tableAlias+tmpcolname;
					sqlwhere_con+=" in ("+multiselectValue +") ";
				}
			}else if(htmltype.equals("3") && BrowserHelper.isSingleBrowserField(type)&&!"".equals(multiselectValue)){//自定义单选  多选
				sqlwhere_con += "and ("+tableAlias+tmpcolname+" in ('"+multiselectValue.replaceAll(",","','")+"')";
			}else  if("3".equals(htmltype)&&("161".equals(type)||"162".equals(type))&&"sqlserver".equals(vdatasourceDBtype)){
				sqlwhere_con += " and  (','+CONVERT(varchar(max),"+tableAlias+tmpcolname+")+',' ";
				sqlwhere_con+=" like '%,"+Util.StringReplace(Util.StringReplace(Util.StringReplace(tmpvalue,"/","//"),"[","/["),"]","/]") +",%' ESCAPE '/' ";
			}//职位安全级别end
			else if(htmltype.equals("3") &&( type.equals("2") || type.equals("19") || type.equals("290"))){    //日期 > >= = < !  and > >= = < !
				if(type.equals("2")){
					Map<String,String> map = getDateRangeByDateField(tmpvalue_select, tmpvalue_start, tmpvalue_end);
					tmpvalue = map.get("startdate");
					tmpvalue1 = map.get("enddate");
					if("".equals(tmpvalue)&&"".equals(tmpvalue1)){
						continue;
					}
				}else if(type.equals("290")){
					//防止条件参数出现中文逗号
					//if(tmpvalue.contains("，")){
					//    tmpvalue=tmpvalue.replace("，", ",");
					//}
					if (!"".equals(tmpvalue_end)) {
						tmpvalue = "".equals(tmpvalue_start) ? "" : new DateTransformer().getServerDateTime(tmpvalue_start);
						tmpvalue1 = "".equals(tmpvalue_end) ? "" : new DateTransformer().getServerDateTime(tmpvalue_end);

					}else{
						continue;
					}
				}else{
					tmpvalue = tmpvalue_start;
					tmpvalue1 = tmpvalue_end;
				}
				if(!tmpvalue.equals("")){
					sqlwhere_con += "and ("+tableAlias+tmpcolname;
					sqlwhere_con+=" >='"+tmpvalue +"' ";
				}
				if(!tmpvalue1.equals("")){
					sqlwhere_con += " and "+tableAlias+tmpcolname;
					sqlwhere_con+=" <='"+tmpvalue1 +"' ";
				}
			}
			else if("3".equals(htmltype) && type.equals("141")){
				List<String> tmpvalueArray = null;
				if(FormModeBrowserUtil.isMultiBrowser(htmltype, type)) {
					tmpvalueArray = Util.splitString2List(tmpvalue, "~");
				} else {
					tmpvalueArray = new ArrayList<String>();
					tmpvalueArray.add(tmpvalue);
				}
				sqlwhere_con += " and ( ";
				boolean first  = true;
				for(String _tmpvalue : tmpvalueArray) {
					if(first) {
						first = false;
					} else {
						sqlwhere_con += " or ";
					}
					if(vdatasourceDBtype.equalsIgnoreCase("oracle") || vdatasourceDBtype.equalsIgnoreCase("db2"))
						sqlwhere_con += " "+tableAlias+tmpcolname+" ";
					else if(vdatasourceDBtype.contains("mysql"))
						sqlwhere_con += " "+tableAlias+tmpcolname+" ";

					else if(vdatasourceDBtype.equals("postgresql"))
						sqlwhere_con += " "+tableAlias+tmpcolname+" ";
					else
						sqlwhere_con += " CONVERT(varchar(max),"+tableAlias+tmpcolname+") ";
					sqlwhere_con+=" like '%"+_tmpvalue +"%' ";
				}
			}
			else if (htmltype.equals("3") || htmltype.equals("6")){   //其他浏览框
				List<String> tmpvalueArray = null;
				if(FormModeBrowserUtil.isMultiBrowser(htmltype, type)) {
					tmpvalueArray = Util.splitString2List(tmpvalue, ",");
				} else {
					tmpvalueArray = new ArrayList<String>();
					tmpvalueArray.add(tmpvalue);
				}
				sqlwhere_con += " and ( ";
				boolean first  = true;
				for(String _tmpvalue : tmpvalueArray) {
					if(first) {
						first = false;
					} else {
						sqlwhere_con += " or ";
					}
					if(vdatasourceDBtype.equalsIgnoreCase("oracle") || vdatasourceDBtype.equalsIgnoreCase("db2"))
						sqlwhere_con += " ','||"+tableAlias+tmpcolname+"||',' ";
					else if(vdatasourceDBtype.contains("mysql"))
						sqlwhere_con += " CONCAT(',',"+tableAlias+tmpcolname+",',') ";
					else if(vdatasourceDBtype.equalsIgnoreCase("postgresql") )
						sqlwhere_con += " ','||"+tableAlias+tmpcolname+"||',' ";
					else
						sqlwhere_con += " ','+CONVERT(varchar(max),"+tableAlias+tmpcolname+")+',' ";
					sqlwhere_con+=" like '%,"+_tmpvalue +",%' ";
				}
			}
			if (htmltype.equals("1")|| htmltype.equals("2")||(htmltype.equals("3") && (type.equals("1")||type.equals("9")||type.equals("4")||type.equals("7")||type.equals("8")||type.equals("16")))||(htmltype.equals("3") && type.equals("24"))||(htmltype.equals("3") &&( type.equals("2") || type.equals("19")))) {
				if(!tmpvalue.equals("")){
					sqlwhere_con +=") ";
				}else if(!multiselectValue.equals("")){
					sqlwhere_con +=") ";
				}
			}else{
				if(!sqlwhere_con.isEmpty()) {
					sqlwhere_con += ") ";
				}
			}
		}
		return sqlwhere_con;
	}


	public List <BrowDefFieldConfEntity> getBdfConfig(Map<String, Object> params){
		int workflowid = Util.getIntValue(Util.null2String(params.get("workflowid")));
		int browserType = Util.getIntValue(Util.null2String(params.get("type")));
		int fieldid = Util.getIntValue(Util.null2String(params.get("fieldid")));
		int viewtype = Util.getIntValue(Util.null2String(params.get("viewtype")));
		String isFromMode = Util.null2o(Util.null2String(params.get("isFromMode")));
		int modeid = Util.getIntValue(Util.null2String(params.get("modeId")));
		int customid = -1;
		List <BrowDefFieldConfEntity> configs = new ArrayList <BrowDefFieldConfEntity>();
		ConditionType conditionType = null;
		RecordSet rs = new RecordSet();
		String sql="select customid from  MODE_BROWSER m left join  workflow_billfield w on m.showname =  REPLACE(w.fielddbtype,'browser.','')  where  w.id = ?";
		rs.executeQuery(sql,fieldid);
		if(rs.next()){
			customid = Util.getIntValue(Util.null2String(rs.getString("customid")));
		}
		sql ="select m.id,m.fieldid, w.fieldname,m.shownamelabel,m.queryorder,m.conditionTransition,w.fieldhtmltype,w.type,w.fielddbtype,w.qfws from  mode_CustombrowserDspField  m left join  workflow_billfield w  on m.fieldid = w.id  where customid = ? and isquery = 1  order by  m.queryorder,m.showorder,w.id";
		rs.executeQuery(sql,customid);
		while (rs.next()){
			int id = rs.getInt("id");
			String f_id = rs.getString("fieldid");//字段id
			String namestr = "con"+f_id+"_value";
			String domkey = namestr;
			String fieldname = Util.null2String(rs.getString("fieldname"));
			String fieldhtmltype = Util.null2String(rs.getString("fieldhtmltype"));
			String fielddbtype = Util.null2String(rs.getString("fielddbtype"));
			String type = Util.null2String(rs.getString("type"));
			String qfws = Util.null2String(rs.getString("qfws"));
			String conditionfieldtype = "";
			String conditionE9type = "";
			String fieldBrowserType = "";
			String disabled = "";
			String ismultbrowser = "";
			String expandfieldnames ="";
			float defaultshoworder = Util.getFloatValue(rs.getString("queryorder"));
			String namelabel = rs.getString("shownamelabel");
			int shownamelabel = Util.getIntValue(rs.getString("shownamelabel"),0);
			int conditionTransition = Util.getIntValue(rs.getString("conditionTransition"),0);
			if("1".equals(fieldhtmltype)&&"4".equals(type)){//金额转换默认2位小数
				qfws="2";
			}
			if("-1".equals(f_id)){
				fieldname ="modedatacreatetime";
				if(shownamelabel==0){
					namelabel = "722";
				}
				fieldhtmltype = "3";
				type="2";
				domkey = "con"+f_id+"_value_select";
				conditionType = ConditionType.DATE;
			}else if("-3".equals(f_id)){
				fieldname ="id";
				if(shownamelabel==0){
					namelabel = "81287";
				}
				fieldhtmltype = "1";
				type="1";
				conditionType = ConditionType.INPUT;
			}else if("-2".equals(f_id)){
				fieldname = "modedatacreater";
				if(shownamelabel==0){
					namelabel = "882";
				}
				fieldhtmltype = "3";
				type="1";
				conditionType = ConditionType.BROWSER;
			}else if("-5".equals(f_id)){
				fieldname = "modedatastatus";
				if(shownamelabel==0){
					namelabel = "385992";
				}
				fieldhtmltype = "5";
				conditionType = ConditionType.SELECT;
			}else if("-7".equals(f_id)){
				fieldname = "modedatamodifier";
				if(shownamelabel==0){
					namelabel = "3002";
				}
				fieldhtmltype = "3";
				type="1";
				conditionType = ConditionType.BROWSER;
			}else if("-8".equals(f_id)){
				fieldname = "modedatamodifydatetime";
				if(shownamelabel==0){
					namelabel = "516915";
				}
				fieldhtmltype = "3";
				type="290";
				conditionType = ConditionType.RANGEPICKER;
			}else if("1".equals(fieldhtmltype)){//单行文本
				if("2".equals(type)||"3".equals(type)||"4".equals(type)||"5".equals(type)){
					conditionType = ConditionType.SCOPE;
					domkey = "con"+f_id+"_value_start";
				}else{
					conditionType = ConditionType.INPUT;
				}
			}else if("2".equals(fieldhtmltype)){//多行文本
				conditionType = ConditionType.INPUT;
			}else if(fieldhtmltype.equals("3")){
				if("2".equals(type)){
					conditionType = ConditionType.DATE;
					domkey = "con"+f_id+"_value_select";
				}else if("19".equals(type)){
					conditionType = ConditionType.TIMERANGEPICKER;
					domkey = "con"+f_id+"_value_start";
				}else if("290".equals(type)){
					conditionType = ConditionType.RANGEPICKER;
				}else if("402".equals(type) || "403".equals(type)){
					conditionType = ConditionType.DATEPICKER;
				}else{
					conditionType = ConditionType.BROWSER;
				}
				if(BrowserHelper.isSingleBrowserField(type)&&conditionTransition==1){
					domkey="multiselectValue_con"+f_id+"_value";
				}
			}else if(fieldhtmltype.equals("4")){
				conditionType = ConditionType.SELECT;
			}else if(fieldhtmltype.equals("5")){
				conditionType = ConditionType.SELECT;
				if(conditionTransition==1) {
					domkey="multiselectValue_con"+f_id+"_value";
				}else {
					if (type.equals("2")) {//选择框多选
						domkey="multiselectValue_con"+f_id+"_value";
					}
				}
			}else if(fieldhtmltype.equals("6")){
				conditionType = ConditionType.BROWSER;
			}
			fieldBrowserType = type;
			if("3".equals(fieldhtmltype)&&"290".equals(type)||fieldhtmltype.equals("6")||"4".equals(fieldhtmltype)&&"1".equals(type)){//日期时间,附件,check不支持
				continue;
			}
			BrowDefFieldConfEntity config = new BrowDefFieldConfEntity();
			config.setId(id);
			config.setFieldid(Util.getIntValue(f_id));
			config.setFieldhtmltype(fieldhtmltype);
			config.setFieldtype(type);
			config.setFielddbtype(fielddbtype);
			config.setQfws(qfws);
			config.setFieldname(domkey);
			config.setNamelabel(namelabel);
			config.setConditionFieldType(conditionfieldtype);
			config.setDefaultshowOrder(defaultshoworder);
			config.setConditionType(BrowserDataDefinitionBiz.e9ConditionTypeStringToEnum(conditionE9type));
			config.setBrowserType(fieldBrowserType);
			config.setDisabled("1".equals(disabled));
			config.setMultBrowser("1".equals(ismultbrowser));
			config.setExpandfieldnames(expandfieldnames);
			config.setConditionType(conditionType);
			configs.add(config);
		}
		return configs;
	}

	/***
	 * 获取浏览数据定义-浏览框的高级查询信息
	 * @param params
	 * @return
	 */
	public Map<String, Object> getConditionConfigInfo(Map<String, Object> params){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		int workflowid = Util.getIntValue(Util.null2String(params.get("workflowid")));
		int browserType = Util.getIntValue(Util.null2String(params.get("type")));
		int fieldid = Util.getIntValue(Util.null2String(params.get("fieldid")));
		int viewtype = Util.getIntValue(Util.null2String(params.get("viewtype")));
		String isFromMode = Util.null2o(Util.null2String(params.get("isFromMode")));
		int modeid = Util.getIntValue(Util.null2String(params.get("modeId")));
		ModeComInfo modeComInfo = new ModeComInfo();
		int formid = Util.getIntValue(modeComInfo.getFormId(String.valueOf(modeid)));
		workflowid = -1*modeid;
		int isbill = 1;
		String groupid = Util.null2String(params.get("groupid"));
		List<BrowDefFieldConfEntity> configs = getBdfConfig(params);
		Map<Integer, WeaTableEditComEntity> selectMap = BrowserDataDefinitionBiz.getBdfSelectCondition(browserType, workflowid,viewtype,groupid,user);
		Map<Integer, WfBdfDataEntity> bdfData = BrowserDataDefinitionBiz.getFieldBdfData(workflowid, fieldid, viewtype);
		Map<String,FieldInfoEntity> wfBrowserFields = BrowserDataDefinitionBiz.getFormBrowserFieldInfo(formid,isbill,user);

		List<Map<String, Object>> datas = new ArrayList<Map<String, Object>>();
		ConditionFactory conditionFactory = new ConditionFactory(user);

		Map<String, Object> selectedData = new HashMap<String, Object>();
		List<Integer> hideSelecteds = new ArrayList<Integer>();
		List<Integer> readOnlySelecteds = new ArrayList<Integer>();
		selectedData.put("hide", hideSelecteds);
		selectedData.put("readOnly", readOnlySelecteds);


		for (BrowDefFieldConfEntity rdfcEntity : configs) {
			Map<String, Object> rowData = new HashMap<String, Object>();
			Map<String, Object> com = new HashMap<String, Object>();
			int configid = rdfcEntity.getId();
			rowData.put("id", configid);
			rowData.put("fieldhtmltype", rdfcEntity.getFieldhtmltype());
			rowData.put("fieldtype", rdfcEntity.getFieldtype());
			rowData.put("qfws", rdfcEntity.getQfws());
			rowData.put("fieldname", rdfcEntity.getFieldname());
			rowData.put("label", SystemEnv.getHtmlLabelNames(rdfcEntity.getNamelabel(), user.getLanguage()));
			rowData.put("com", com);


			if(rdfcEntity.isDisabled()) {
				Map<String,Object> checkProps  = new HashMap<String,Object>();
				Map<String,Object> hideCheckProps  = new HashMap<String,Object>();
				Map<String,Object> readOnlyCheckProps  = new HashMap<String,Object>();
				hideCheckProps.put("viewAttr",1);
				readOnlyCheckProps.put("viewAttr",1);
				checkProps.put("hide",hideCheckProps);
				checkProps.put("readOnly",readOnlyCheckProps);
				rowData.put("checkProps",checkProps);
			}
			WfBdfDataEntity bdfDataEntity = bdfData.get(configid);
			com.put("fieldCom", getCol2Coms(rdfcEntity, selectMap, conditionFactory, workflowid,bdfDataEntity,rowData));

			int showOrder = -1;
			if (bdfDataEntity != null) {
				showOrder = bdfDataEntity.getShoworder();
				if (bdfDataEntity.isHide()) hideSelecteds.add(showOrder);
				if (bdfDataEntity.isReadOnly()) readOnlySelecteds.add(showOrder);
				setFieldValue(bdfDataEntity, rdfcEntity, selectMap, rowData,wfBrowserFields);
			}else{
				String fieldhtmltype = rdfcEntity.getFieldhtmltype();
				String fieldtype = rdfcEntity.getFieldtype();
				if("3".equals(fieldhtmltype) && ("402".equals(fieldtype) ||"403".equals(fieldtype))){
					rowData.put("fieldvalue", "");
				}
			}

			if (showOrder == -1) {
				datas.add(rowData);
			} else if (datas.size() - 1 > showOrder) {
				datas.add(showOrder, rowData);
			} else {
				datas.add(rowData);
			}
		}
		apidatas.put("selectedData", selectedData);
		apidatas.put("columns", getTableCoulumns());
		apidatas.put("datas", datas);

		return apidatas;
	}

	/**
	 * 解析条件组件
	 * @param rdfcEntity
	 * @param selectMap
	 * @param conditionFactory
	 * @param workflowid
	 * @param bdfDataEntity
	 * @return
	 */
	private List<WeaTableEditComEntity> getCol2Coms(BrowDefFieldConfEntity rdfcEntity, Map<Integer, WeaTableEditComEntity> selectMap, ConditionFactory conditionFactory, int workflowid,WfBdfDataEntity bdfDataEntity,Map<String, Object> rowData) {
		List<WeaTableEditComEntity> col2Coms = new ArrayList<WeaTableEditComEntity>();
		//String fieldid = Util.null2String(rdfcEntity.getId());
		String fieldid = Util.null2String(rdfcEntity.getFieldid());
		String fieldhtmltype = Util.null2String(rdfcEntity.getFieldhtmltype());
		String fieldtype = Util.null2String(rdfcEntity.getFieldtype());
		String fielddbtype = Util.null2String(rdfcEntity.getFielddbtype());
		RecordSet rs = new RecordSet();

		WeaTableEditComEntity com2 = new WeaTableEditComEntity();
		col2Coms.add(com2);
		com2.setEditType("1");
		com2.setKey("fieldvalue");
		com2.setType(ConditionType.CUSTOM);

		if("5".equals(fieldhtmltype)){
			char flag=2;
			List<SearchConditionOption> options2 = new ArrayList<SearchConditionOption>();
			SearchConditionOption opt = new SearchConditionOption();
			opt.setKey("");
			opt.setShowname("");
			options2.add(opt);
			rs.executeProc("workflow_SelectItemSelectByid",""+fieldid+flag+"1");
			while(rs.next()){
				int tmpselectvalue = rs.getInt("selectvalue");
				String tmpselectname = rs.getString("selectname");

				String tempcancel = rs.getString("cancel");
				if("1".equals(tempcancel)){
					continue;
				}
				SearchConditionOption options = new SearchConditionOption();
				options.setKey(tmpselectvalue+"");
				options.setShowname(tmpselectname);
				options2.add(options);
			}
			com2.setOptions(options2);
		}else{
			if("3".equals(fieldhtmltype)) {
				com.api.browser.bean.BrowserBean browserProps = null;
				if("161".equals(fieldtype) || "162".equals(fieldtype)) {
					String key = fieldtype+"_browser."+fielddbtype;
					browserProps = new com.api.browser.bean.BrowserBean(fieldtype);
					new BrowserInitUtil().initCustomizeBrow(browserProps,fielddbtype, Util.getIntValue(fieldtype) , user.getUID());
					browserProps.getDataParams().put("formmodefieldid",fieldid);
					browserProps.getConditionDataParams().put("formmodefieldid", fieldid);
					browserProps.getCompleteParams().put("formmodefieldid", fieldid);
				} else if("256".equals(fieldtype) || "257".equals(fieldtype)) {
					browserProps = new com.api.browser.bean.BrowserBean(fieldtype);
					browserProps.getDataParams().put("cube_treeid", fielddbtype);
					browserProps.getCompleteParams().put("cube_treeid", fielddbtype);
					new BrowserInitUtil().initBrowser(browserProps,user.getLanguage());
				} else if("226".equals(fieldtype)){	//SAP单选

				} else {
					browserProps = new com.api.browser.bean.BrowserBean(fieldtype);
					new BrowserInitUtil().initBrowser(browserProps,user.getLanguage());
				}
				//field.put("browserProps", browserProps);
				com2.setBrowserConditionParam(browserProps);
			}
		}
		return col2Coms;
	}
	/**
	 * 维度
	 *
	 * @param conditionFactory
	 * @return
	 */
	public List<SearchConditionOption> getVirtualOptions(ConditionFactory conditionFactory,Map<String, Object> rowData) {
		CompanyComInfo companyComInfo = new CompanyComInfo();
		CompanyVirtualComInfo companyVirtualComInfo = new CompanyVirtualComInfo();
		companyVirtualComInfo.setUser(user);
		List<SearchConditionOption> options2 = new ArrayList<SearchConditionOption>();
		boolean selected = true;
		if (companyComInfo.getCompanyNum() > 0) {
			companyComInfo.setTofirstRow();
			while (companyComInfo.next()) {
				options2.add(new SearchConditionOption(companyComInfo.getCompanyid(), companyComInfo.getCompanyname(),selected));
				if(selected){
					rowData.put("fieldvalue",companyComInfo.getCompanyid());
					selected = false;
				}
			}
		}
		companyVirtualComInfo.setTofirstRow();
		while (companyVirtualComInfo.next()) {
			options2.add(new SearchConditionOption(companyVirtualComInfo.getCompanyid(), companyVirtualComInfo.getVirtualType(),selected));
			if(selected) selected = false;
		}
		return options2;
	}

	private List<WeaTableEditEntity> getTableCoulumns() {
		List<WeaTableEditEntity> columns = new ArrayList<WeaTableEditEntity>();
		//col1
		WeaTableEditComEntity com1 = new WeaTableEditComEntity();
		com1.setType(ConditionType.TEXT);
		com1.setLabel("");
		List<WeaTableEditComEntity> col1Coms = new ArrayList<WeaTableEditComEntity>();
		col1Coms.add(com1);
		WeaTableEditEntity col1 = new WeaTableEditEntity(SystemEnv.getHtmlLabelName(15364, user.getLanguage()), "label", "20%", "1");
		col1.setCom(col1Coms);
		//col2
		WeaTableEditEntity col2 = new WeaTableEditEntity("", "fieldCom", "fieldCom", "50%", "1");
		col2.setUseRecord(true);

		WeaTableEditEntity col3 = new WeaTableEditEntity(SystemEnv.getHtmlLabelName(16636, user.getLanguage()), "hide", "15%", "1");
		col3.setCheckType("checkbox");
		//col4
		WeaTableEditEntity col4 = new WeaTableEditEntity(SystemEnv.getHtmlLabelName(17873, user.getLanguage()), "readOnly", "15%", "1");
		col4.setCheckType("checkbox");
		columns.add(col1);
		columns.add(col2);
		columns.add(col3);
		columns.add(col4);
		return columns;
	}


	/**
	 * 设置默认值
	 *
	 * @param bdfDataEntity
	 * @param conditionType
	 * @return
	 */
	private void setFieldValue(WfBdfDataEntity bdfDataEntity, BrowDefFieldConfEntity rdfcEntity, Map<Integer, WeaTableEditComEntity> selectMap, Map<String, Object> rowData,Map<String,FieldInfoEntity> wfBrowserFields) {
		String fieldvalue = Util.null2String(bdfDataEntity.getValue());
		String fieldhtmltype = rdfcEntity.getFieldhtmltype();
		String fieldtype = rdfcEntity.getFieldtype();
		String fielddbtype = rdfcEntity.getFielddbtype();
		String conditionvalue =  Util.null2String(bdfDataEntity.getConditionvalue());
		String conditionvalue1 =  Util.null2String(bdfDataEntity.getConditionvalue1());
		String conditionvalue2 =  Util.null2String(bdfDataEntity.getConditionvalue2());
		List<BrowserValueInfo> replaceDatas;
		BrowserValueInfoService browserValueInfoService = new BrowserValueInfoService();
		rowData.put("selecttype","".equals(bdfDataEntity.getSelecttype())?-1:bdfDataEntity.getSelecttype());

		if (bdfDataEntity.getSelecttype() == -2) {//模块字段
			RecordSet rs = new RecordSet();
			ModeFieldTransmethod modeFieldTransmethod = new ModeFieldTransmethod();
			String sql = "select t1.id,t1.fieldname, t1.fieldlabel, t1.viewtype, t1.dsporder, " +
					"t1.detailtable, t1.fieldhtmltype, t1.type  from workflow_billfield t1 where id = ? ";

			rs.executeQuery(sql, fieldvalue);
			if (rs.next()) {
				String fieldLabel = Util.null2String(rs.getString("fieldlabel"));
				String viewtype = Util.null2String(rs.getString("viewtype"));
				String fieldvaluename = modeFieldTransmethod.getHtmlLabelName(fieldLabel, fieldvalue + "+" + viewtype + "+" + user.getLanguage());

				JSONArray fieldvalueReplaceDatas = new JSONArray();
				JSONObject obj = new JSONObject();
				obj.put("id", fieldvalue);
				obj.put("name", fieldvaluename);
				fieldvalueReplaceDatas.add(obj);
				rowData.put("fieldvalue", fieldvalueReplaceDatas);
			}
		} else {
			if ("1".equals(fieldhtmltype)) {
				if ("1".equals(fieldtype)) {
					rowData.put("fieldvalue", fieldvalue);
				} else {//金额类型
					rowData.put("fieldvalue", new String[]{conditionvalue, conditionvalue1});   //条件参数
				}
			} else if ("2".equals(fieldhtmltype)) {
				rowData.put("fieldvalue", fieldvalue);
			} else if ("3".equals(fieldhtmltype)) {
				if ("2".equals(fieldtype) || "19".equals(fieldtype) || "290".equals(fieldtype)) {   //日期 时间
					if("2".equals(fieldtype)){   //日期
						if(Util.getIntValue(conditionvalue) > 0 && !"6".equals(conditionvalue)) {
							rowData.put("fieldvalue", new String []{conditionvalue,"",""});
						} else if("".equals(conditionvalue)||"0".equals(conditionvalue)){
							rowData.put("fieldvalue", new String []{"0","",""});
						}else {
							rowData.put("fieldvalue", new String []{"6",conditionvalue1,conditionvalue2});
						}
					} else if("19".equals(fieldtype)){    //时间
						if(Util.getIntValue(conditionvalue) > 0) {
							rowData.put("fieldvalue", new String []{conditionvalue,"",""});
						} else {
							rowData.put("fieldvalue", new String []{conditionvalue,conditionvalue1});
						}
					}else if("290".equals(fieldtype)) {
						if(Util.getIntValue(conditionvalue) > 0) {
							rowData.put("fieldvalue", new String []{ new DateTransformer().getLocaleDateTime(conditionvalue) ,"",""});
						} else {
							rowData.put("fieldvalue", new String []{new DateTransformer().getLocaleDateTime(conditionvalue) ,new DateTransformer().getLocaleDateTime(conditionvalue1)});
						}
					}
				} else if("402".equals(fieldtype) || "403".equals(fieldtype)){//年月
					rowData.put("fieldvalue", fieldvalue);
				} else {
					try {
						if (!"".equals(fieldvalue)) {
							replaceDatas = browserValueInfoService.getBrowserValueInfo(fieldtype, fielddbtype, 0, fieldvalue, user.getLanguage(), "", "");
							replaceDatas = BrowserHelper.deleteEmptyReplaceDatas(replaceDatas);
							rowData.put("fieldvalue", replaceDatas);
						}
					} catch (Exception e) {
						writeLog(e);
					}
				}
			} else {
				rowData.put("fieldvalue", fieldvalue);   //条件参数
			}
		}
	}


	public Map<String, Object> SaveCondition (Map<String, Object> params){
		Map<String, Object> apidatas = new HashMap<String, Object>();
		int workflowid = Util.getIntValue(Util.null2String(params.get("workflowid")));
		int fieldid = Util.getIntValue(Util.null2String(params.get("fieldid")));
		int type = Util.getIntValue(Util.null2String(params.get("type")));
		int viewtype = Util.getIntValue(Util.null2String(params.get("viewtype")));
		String isFromMode = Util.null2o(Util.null2String(params.get("isFromMode")));
		int modeid = Util.getIntValue(Util.null2String(params.get("modeId")));
		List<BrowDefFieldConfEntity> configs = getBdfConfig(params);
		String insertSql = "insert into workflow_browdef_field(configid,workflowid,modeid,fieldid,viewtype,showorder,hide,readonly,canselectvalues,valuetype,value,selecttype,conditionvalue,conditionvalue1,conditionvalue2) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		List<List<Object>> insertParams = new ArrayList<List<Object>>();
		for (BrowDefFieldConfEntity bdfEntity : configs) {
			int configid = bdfEntity.getId();
			String fieldhtmltype = bdfEntity.getFieldhtmltype();
			String fieldtype = bdfEntity.getFieldtype();
			ConditionType conditionType = bdfEntity.getConditionType();

			String hide = Util.null2String(params.get(configid + "_hide"));
			String readonly = Util.null2String(params.get(configid + "_readOnly"));
			String showorder = Util.null2String(params.get(configid + "_showorder"));
			String value = Util.null2String(params.get(configid + "_fieldvalue"));

			String conditionValue= "", conditionValue1= "", conditionValue2= "";

			if("1".equals(fieldhtmltype)) {
				if("1".equals(fieldtype)) {
					conditionValue = value;
				} else {
					value = value.replace("[","").replace("]","").replace("\"","");
					String[] arr = Util.splitString(value, ",");
					if(arr.length>0) {
						conditionValue = Util.null2String(arr[0]);
						if(arr.length>1) {
							conditionValue1 = Util.null2String(arr[1]);
						}
					}
					if(",".equals(value)){
						value="";
					}
					//value="";//金额类型的 把 value 置空 存储  conditionValue  conditionValue1
				}
			}else if("3".equals(fieldhtmltype)){
				if("2".equals(fieldtype)) {
					value = value.replace("[","").replace("]","").replace("\"","");
					String [] arr = Util.splitString(value,",");
					if(arr.length>0) {
						if(Util.getIntValue(arr[0]) != 6) {
							conditionValue = Util.null2String(arr[0]);
						} else {
							if(arr.length>0){
								conditionValue = Util.null2String(arr[0]);
							}
							if(arr.length>1) {
								conditionValue1 = Util.null2String(arr[1]);
								if(arr.length>2) {
									conditionValue2 = Util.null2String(arr[2]);
								}
							}
						}
					}
					if(",".equals(value)){
						value="";
					}
				} else if("19".equals(fieldtype)) {
					value = value.replace("[","").replace("]","").replace("\"","");
					String [] arr = Util.splitString(value,",");
					if(arr.length>0) {
						conditionValue = Util.null2String(arr[0]);
						if(arr.length>1) {
							conditionValue1 = Util.null2String(arr[1]);
						}
					}
					if(conditionValue.indexOf("value")>-1){
						conditionValue= "";
					}
					if(",".equals(value)){
						value="";
					}
				} else if("290".equals(fieldtype)) {
					value = value.replace("[","").replace("]","").replace("\"","");
					String [] arr = Util.splitString(value,",");
					if(arr.length>0) {
						conditionValue = new DateTransformer().getServerDateTime(Util.null2String(arr[0]));
						if(arr.length>1) {
							conditionValue1 = new DateTransformer().getServerDateTime(Util.null2String(arr[1]));
						}
					}
					if(",".equals(value)){
						value="";
					}
				}
			}
			if(conditionValue1.indexOf("[")>-1||conditionValue1.indexOf("\\")>-1){
				conditionValue1 = "";
				conditionValue2 = "";
			}
			String valuetype = Util.null2String(params.get(configid + "_valuetype"));
			String canselectvalues = Util.null2String(params.get(configid + "_canselectvalues"));
			int selecttype = Util.getIntValue(Util.null2String(params.get(configid + "_selecttype")),-1);
			if(conditionType == ConditionType.SELECT) {
				valuetype = value;
			}

			List<Object> rowParam = new ArrayList<Object>();
			rowParam.add(configid);
			rowParam.add(workflowid);
			rowParam.add(modeid);
			rowParam.add(fieldid);
			rowParam.add(viewtype);
			rowParam.add(showorder);
			rowParam.add(hide);
			rowParam.add(readonly);
			rowParam.add(canselectvalues);
			rowParam.add(valuetype);
			rowParam.add(value);
			rowParam.add(selecttype);
			rowParam.add(conditionValue);
			rowParam.add(conditionValue1);
			rowParam.add(conditionValue2);
			insertParams.add(rowParam);
		}

		RecordSetTrans rst = new RecordSetTrans();
		rst.setAutoCommit(false);

		try {
			rst.executeUpdate("delete from workflow_browdef_field where modeid = ?  and fieldid = ? and (workflowid  is null  or workflowid =-1)  ", modeid, fieldid);
			rst.executeBatchSql(insertSql, insertParams);
			rst.commit();
			apidatas.put("success", true);
		} catch (Exception e) {
			e.printStackTrace();
			rst.rollback();
			apidatas.put("success", false);
		}
		return apidatas;
	}



	//解析PARM参数
	public String  getPARMvalue(String sqlwhere,Map<String, Object> params) {

		if(sqlwhere.indexOf("PARM(")>-1){
			int beginIndex = sqlwhere.indexOf("PARM(");
			while(beginIndex>-1){
				int endIndex = sqlwhere.indexOf(")",beginIndex+5);
				int nextIndex = 0;
				if(endIndex>-1){
					String substring = sqlwhere.substring(beginIndex+5, endIndex);
					if(params.get(substring)==null){
						beginIndex = sqlwhere.indexOf("PARM(",endIndex-nextIndex+1);
					}else{
						String paramvalue = Util.null2String(params.get(substring));
						sqlwhere = sqlwhere.replace("PARM("+substring+")", paramvalue);
						if(paramvalue.length()<substring.length()){
							nextIndex = sqlwhere.length()-paramvalue.length();
						}
						beginIndex = sqlwhere.indexOf("PARM(",endIndex-nextIndex+1);
					}
				}else{
					break;
				}
			}
		}
		return sqlwhere;

	}
	//获取数据定义配置的数据范围
	public Map<String, Object> getBrowserDataDefinition(String sqlwhere, Map<String, Object> params,String searchByName) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			String datasql = "";
			boolean havebdf = false;//是否配置了数据范围
			RecordSet rs = new RecordSet();
			FormModeTransMethod formModeTransMethod = new FormModeTransMethod();
			int fieldid = Util.getIntValue(Util.null2String(params.get("fieldid")));
			int modeId = Util.getIntValue(Util.null2String(params.get("modeId")));
			String tablename = "";
			rs.executeQuery("select conditiontype,conditionsql,conditiontext from mode_data_definition where fieldid=? and modeid =?", fieldid, modeId);
			if (rs.next()) {
				datasql = rs.getString("conditionsql");
				datasql = formModeTransMethod.getDefaultSql(user, datasql);
				sqlwhere += " where " + datasql;
			}
			if (!"".equals(datasql)) {//配置了数据定义规则就以数据定义规则为准
				sqlwhere = searchByName.substring(0, searchByName.indexOf("where"));//获取基础的sql
				sqlwhere += " where " + datasql;
				havebdf = true;
			}
			map.put("search",sqlwhere);
			map.put("havebdf",havebdf);
		} catch (Exception e) {
			writeLog(e);
		}
		return map;
	}

	private String removeParam(String sql) {
		sql = sql.replaceAll("\\([ ]+\\{\\?", "({?");//对自定义变量的特殊处理

		//对括号的特殊处理
		sql = sql.replaceAll("\\(", " ( ");
		sql = sql.replaceAll("\\)", " ) ");

		//in和not in特殊情况处理
		sql = sql.replaceAll("[\\s]+[_a-zA-Z0-9.]+[\\s]+((not|NOT)[\\s]+)?(in|IN)[\\s]+[\\(][\\s]*''''[\\s]*[\\)][\\s]+", " 1=1 ");
		sql = sql.replaceAll("[\\s]+[_a-zA-Z0-9.]+[\\s]+((not|NOT)[\\s]+)?(in|IN)[\\s]+[\\(][\\s]*[']?(\\$|\\{\\?)[_a-zA-Z0-9]+(\\$|\\})[']?[\\s]*[\\)][\\s]+", " 1=1 ");
		sql = sql.replaceAll("[\\s]+[_a-zA-Z0-9.]+[\\s]+((not|NOT)[\\s]+)?(in|IN)[\\s]+[\\(][\\s]*'*[\\s]*'*[\\s]*[\\)][\\s]+", " 1=1 ");
		//like和not like特殊情况处理
		sql = sql.replaceAll("[\\s]+[_a-zA-Z0-9.]+[\\s]+((not|NOT)[\\s]+)?(like|LIKE)[\\s]+[\\(]?[\\s]*[']?%?[,|.|/|\\|，|。|;|；]?(\\$|\\{\\?)[_a-zA-Z0-9]+(\\$|\\})[,|.|/|\\|，|。|;|；]?%?[']?[\\s]*[\\)]?[\\s]+", " 1=1 ");
		sql = sql.replaceAll("'%''%'", "'%%'");
		//去除between and
		sql = sql.replaceAll("[\\s]+[_a-zA-Z0-9.]+[\\s]+((not|NOT)[\\s]+)?(between|BETWEEN)[\\s]+[']?(\\$|\\{\\?)[_a-zA-Z0-9]+(\\$|\\})[']?[\\s]+(and|AND)[\\s]+[']?(\\$|\\{\\?)[_a-zA-Z0-9]+(\\$|\\})[']?[\\s]+", " 1=1 ");

		//id=$fieldname$ id=$userid$
		sql = sql.replaceAll("[\\s]+[_a-zA-Z0-9.]+[\\s]*[=<>!]{1,2}[\\s]*[']?(\\$|\\{\\?)[_a-zA-Z0-9]+(\\$|\\})[']?[\\s]+", " 1=1 ");
		//$fieldname$=id  $userid$=id
		sql = sql.replaceAll("[\\s]+[']?(\\$|\\{\\?)[_a-zA-Z0-9]+(\\$|\\})[']?[\\s]*[=<>!]{1,2}[\\s]*[_a-zA-Z0-9.]+[\\s]+", " 1=1 ");

		sql = sql.replaceAll("([ \\s\\(]+)[_a-zA-Z0-9.]*[\\(]?[_a-zA-Z0-9,.]*[']?[%]?\\$[_a-zA-Z0-9]+\\$[%]?[']?[_a-zA-Z0-9,.]*[\\)]?[ \\s]*([=<>!]{1,2}|not[\\s]+like|like|not[\\s]+in|in|NOT[\\s]+LIKE|LIKE|NOT[\\s]+IN|IN)[\\s]+[_a-zA-Z0-9.,\\(\\)]+([\\) \\s]+)", " $1 1=1 $3 ");
		sql = sql.replaceAll("([ \\s\\(]+)[_a-zA-Z0-9.,\\(\\)]+[ \\s]*([=<>!]{1,2}|not[\\s]+like|like|not[\\s]+in|in|NOT[\\s]+LIKE|LIKE|NOT[\\s]+IN|IN)[ \\s]*[_a-zA-Z0-9.]*[\\(]?[_a-zA-Z0-9,.]*[']?[%]?\\$[_a-zA-Z0-9]+\\$[%]?[']?[_a-zA-Z0-9,.]*[\\s]+[\\)]?([\\) \\s]+)", " $1 1=1 $3 ");
		sql = sql.replaceAll("([ \\s\\(]+)[_a-zA-Z0-9.]*[\\(]?[_a-zA-Z0-9,.]*[']?[%]?\\{\\?[a-z]+\\}[%]?[']?[_a-zA-Z0-9,.]*[\\)]?[ \\s]*([=<>!]{1,2}|not[\\s]+like|like|not[\\s]+in|in|NOT[\\s]+LIKE|LIKE|NOT[\\s]+IN|IN)[ \\s]*[_a-zA-Z0-9.,\\(\\)]+([\\) \\s]+)", " $1 1=1 $3 ");
		sql = sql.replaceAll("([ \\s\\(]+)[_a-zA-Z0-9.,\\(\\)]+[ \\s]*([=<>!]{1,2}|not[\\s]+like|like|not[\\s]+in|in|NOT[\\s]+LIKE|LIKE|NOT[\\s]+IN|IN)[ \\s]*[_a-zA-Z0-9.]*[\\(]?[_a-zA-Z0-9,.]*[']?[%]?\\{\\?[a-z]+\\}[%]?[']?[_a-zA-Z0-9,.]*[\\)]?([\\) \\s]+)", " $1 1=1 $3 ");

		return sql;
	}

	private List<SearchConditionOption> getCheckOptions(int language) {
		List<SearchConditionOption> options = new ArrayList<SearchConditionOption>();
		options.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(332, language)));   //全部
		options.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(30631, language)));   //勾选
		options.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(385734, language)));  //未勾选
		return options;
	}
	//千分位转换
	public String changeToThousands(String value){
		String fh = "";
		if (value.startsWith("-")) {
			value = value.substring(1);
			fh = "-";
		}

		String[] tempvalues = value.split("\\.");
		int precision = 0;
		if(tempvalues.length > 1){
			precision = tempvalues[1].length();
		}
		BigDecimal b = new BigDecimal(value);
		if(value.indexOf(".") == -1){
			String reg = "###,###";
			DecimalFormat d1 =new DecimalFormat(reg);
			value =  d1.format(b);
		}else{
			if(tempvalues[0].equals("0")){
				value= value;
			}else{
				if(tempvalues.length == 2){
					precision = tempvalues[1].length();
				}
				String reg = "###,###.";
				for(int i=0;i<precision;i++){
					reg += "0";
				}
				DecimalFormat d1 =new DecimalFormat(reg);
				value =  d1.format(b);
			}
		}
		return fh + value;
	}


	private List<SearchConditionOption> getDateOptions(int language,int id) {
		List<SearchConditionOption> options = new ArrayList<SearchConditionOption>();
		options.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(332, language)));
		options.add(new SearchConditionOption("9", SystemEnv.getHtmlLabelName(517615, language)));
		options.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(15537, language)));
		if(id>-1)options.add(new SearchConditionOption("10",SystemEnv.getHtmlLabelName(517616, language)));
		options.add(new SearchConditionOption("11",SystemEnv.getHtmlLabelName(517617, language)));
		options.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(15539, language)));
		if(id>-1)options.add(new SearchConditionOption("12",SystemEnv.getHtmlLabelName(517618, language)));
		options.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(15541, language)));
		options.add(new SearchConditionOption("4", SystemEnv.getHtmlLabelName(21904, language)));
		options.add(new SearchConditionOption("5", SystemEnv.getHtmlLabelName(15384, language)));
		options.add(new SearchConditionOption("7", SystemEnv.getHtmlLabelName(27347, language)));
		options.add(new SearchConditionOption("8", SystemEnv.getHtmlLabelName(81716, language)));
		options.add(new SearchConditionOption("6", SystemEnv.getHtmlLabelName(32530, language)));
		return options;
	}

	public boolean isImgSearch() {
		return isImgSearch;
	}

	public void setImgSearch(boolean imgSearch) {
		isImgSearch = imgSearch;
	}

	public String getImgField() {
		return imgField;
	}

	public void setImgField(String imgField) {
		this.imgField = imgField;
	}

	public String getImgIcon() {
		return imgIcon;
	}

	public void setImgIcon(String imgIcon) {
		this.imgIcon = imgIcon;
	}
}
